1. Home
  2. Knowledge Base
  3. WordPress
  4. Set up a staging or working copy for your WordPress website

Set up a staging or working copy for your WordPress website

Whenever you want to introduce changes to your WordPress website, it is a good idea to test them first. Whether you are adding new themes, new plugins or adding new content, you might want to test everything first. This tutorial will show you how to create a working copy (staging copy) of your WordPress website, which you can work on, while your original website is still online. This tutorial will also be helpful if you want to move your WordPress website to another host.

In this article we are using as an example the website http://ninefortwowebhosting.com/. Make sure you substitute that string with your own domain name when you follow the steps.

  1. Create a new subsite. This will be the address of your staging website.
  2. Now copy your official website to staging so you can start editing. Login to SSH. Execute from ssh root directory:
    rsync -rtv www/ subsites/staging.ninefortwowebhosting.com/
    

    This will not be sufficient for your staging copy to work. You also need the database.

  3. You will need certain database details in order to create a backup. Get them from your configuration file by executing the following command:
    cat www/wp-config.php | grep DB_
    

    The output will look something like this:

    define(‘DBNAME’, ‘ID111111user’);
    define(‘DBUSER’, ‘ ID111111user ‘);
    define(‘DBPASSWORD’, XXXXXXXXXX);
    define(‘DB
    HOST’, ‘mysql111.hosting.brand.com’);
    define(‘DBCHARSET’, ‘utf8’);
    define(‘DB
    COLLATE’, ”);

    Make a copy of your database details.

  4. Download a database backup. Download the dump file via rsync or ftp.
  5. Now create the new database that will be used for the staging copy from the control panel.
  6. You can use this tool https://wpdomainchanger.com/ to edit the URLs from the original WordPress to the staging WordPress. Download the altered database dump.
  7. Import the altered database dump
  8. Now you have to update the wp-config.php file of the staging copy with the new DB details. Open the config file like so:
    nano subsites/staging.ninefortwowebhosting.com/wp-config.php
    

    Edit the following strings with the details of the new database you created:

    In this string enter your new database name

    define(‘DBNAME’, ‘ID111111name’);

    In this string enter your new username

    define(‘DBUSER’, ‘ ID111111user ‘);

    In this string enter your new password

    define(‘DB_PASSWORD’, XXXXXXXXXX);

    In this string enter your new database host

    define(‘DB_HOST’, ‘mysql111.hosting.brand.com’);

  9. Now test if your copy works.
Updated on 1 April 2020

Was this article helpful?