If for some reason you created a WordPress site and went straight for what IT developers like to call your production site, and now you want to make changes to the site but don’t want to take a chance damaging it. Then you need a “Test Site.”

It’s usually easier to start with a Test, Model, and finally Production site. Some folks dispense with the Model and only do Test and Production. Problem is if you don’t at least have the Test site, you only have one production site and if something goes wrong it becomes very difficult to recover from catastrophe.

Luckily, duplicating a WordPress site is pretty easy and straightforward process if you know exactly what to do. To duplicate the site you need to perform the steps below. Two of the most important steps are modifying the database and the wp-config files as they are important to have a seamless experience with creating a test site.

However, if all steps are followed the site will work after duplication.

Steps to create a Test WordPress site from a Production copy:

  1. Create a Sub-domain for the Test Site on your main domain (i.e test.your-site-domain.com)
    1. Depending on your hosting provider the steps may differ. However, creating a sub-domain is usually very easy to do. Select the domain you are using. For example, if the site domain is “your-site-domain.com”, you would select that then create a sub-domain such as “test.your-site-domain.com”. Once that sub-domain is created it usually takes a few minutes to up to 24 hours to activate and propagate across DNS servers.
  2. Create a Test Directory for the new Test site and use that as the target for the new sub-domain you previously created.
    1. Now that the sub-domain has been created you need to create a target directory on the hosting web space for the new sub-domain.
    2. Create a directory that is easily recognizable to you for your new sub-domain within the web server structure. For example, if your production web server directory is “you-site-domain” or “www” then name the new directory “test.your-site-domain.com” or even “test-site”. Some folks like to use “staging” so that it clearly identifies that it is their testing site. Whatever you name it, keep it consistent as the naming convention between your sub-domains and web folders keeps continuity between each and makes it easily recognizable.
  3. Create a new database for the test site (Store the database information for later use).
    1. Depending on your hosting provider these steps may differ. However, creating a new database is usually very easy to do. When creating the database you provide a description for the database, a username (usually provided for you, sometimes you create your own) and assign a password. Ensure that the description identifies that its the Test Database for the Test Site, and create a strong password. Usually, the hosting provider will provide the database name, database hostname, port number, username and SQL Version in use. You will need the Database name, hostname, username, and password for later use. Save that information.
  4. Export the production database.
    1. Export the existing production database to a SQL file.
  5. Modify the exported production database.
    1. Open the exported production database file and modify the following lines:
      1. Modify the line “–Host: <enter your new database host>
      2. Modify the line “–Database: <enter your new database>
      3. The above two lines don’t affect the site or database. They are modified for the sake of reflecting the correct information. The next section is what matters.
    2. The database stores links for your site that allows it to function properly, most of the existing links in the database will reflect the production URL. For example, http://www.your-site-.com. These URLs will need to be changed from “www” to “test” or whatever sub-domain you selected to create. The easiest way to change these URLs is to do a FInd and Replace and change all “http://www.your-site-.com” to “http://test.your-site-.com”. This ensures the correct entries are changed. If you perform a Find and Replace only on the words “www” to “test” you may inadvertently change something that is not necessarily a URL and could damage a setting or some other form of data.
  6. Copy the existing WordPress site files.
    1. Using your hosting provider web space manager or FileZilla, download or copy the existing WordPress site from the existing target directory to the new test target directory. When the copy is completed you should have two exact copies of the production WordPress files. One in the Production folder (WWW) and one in the Test Folder (TEST).
  7. Modify the copied wp-config.php file.
    1. After copying the existing production WordPress files, edit the wp-config file and modify the following lines, use the new database information stored previously from step 3:
      1. MySQL Settings ‘DB_NAME’ change the database name to the new Test Database Name.
      2. MySQL database username ‘DB_USER’ change the database username to the new Test Database User.
      3. MySQL database password ‘DB_PASSWORD’ change the database password to the new Test Database Password.
      4. MySQL Hostname ‘DB_HOST’ change the database hostname to the new Test Database Hostname.
  8. Save the edited wp-config file.
    1. If the file was edited on the hosting provider server, save the wp-config file. If the file was edited locally, then remember to Upload the copied and modified wp-config file back to the new sub-domain Test Directory. Or upload all the copied and modified WordPress site files to the new sub-domain Test Directory if they were downloaded using FileZilla and modified locally.
  9. Lastly – Test the new site.

While it may seem like there are a lot of steps, they are fairly easy to do. If performed correctly, you end up with a Test site that can be used to make changes too without affecting the production site. Then when testing has been completed on the test site, you have peace of mind knowing that your changes to a test site will not cause issues on a production one.