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.
- Create a new subsite. This will be the address of your staging website.
- 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.
- 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(‘DBHOST’, ‘mysql111.hosting.brand.com’);
define(‘DBCHARSET’, ‘utf8’);
define(‘DBCOLLATE’, ”);Make a copy of your database details.
- Download a database backup. Download the dump file via rsync or ftp.
- Now create the new database that will be used for the staging copy from the control panel.
- 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.
- Import the altered database dump
- 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’);
- Now test if your copy works.