PHPMatters Help You Better Hosting Your PHP-based Sites
When and How to Create the WordPress Staging Environment

When and How to Create the WordPress Staging Environment

Have you ever found that your site crashes after updating your templates or installing a new plugin? No matter what reason that causes this wrong situation, the reading experience of your visitors, the first impression of new readers and the SEO ranking of your site can be affected negatively.

In this case, we highly recommend you to create a staging site against your live site, with which you can test whether the changes or updates can work on your live version. As many webmasters have no idea where to start, in the following, we’d like to present a tutorial telling you when and how to create the WordPress staging environment easily.

When to Create the WordPress Staging Environment

The staging site is a separate and independent version of your live site, with which you can start the worry-free testing for plugins, templates, software, coding changes, the new release of WordPress and many more. Therefore, once you are willing to make some changes on your live site, you’d better test them on your staging site initially. If there is nothing wrong happened, you can carry out the changes on the live version without any worry.

In the following, we have listed some common situations when you may need to create the staging environment.

  • If you are going to make an update on your WordPress core, templates or plugins, you need to make these changes on your staging site to ensure there are no conflict issues.
  • If you want to install a new plugin or application, you’d better start a testing initially to make sure that all the newly-installed items are 100% compatible with your current site.
  • If you are going to make the customization on your current template, the staging environment can prevent your readers from seeing your working process.
  • If you are a developer who wants to add the custom code on your WordPress site, the initial testing on the staging site is a critical step to avoid the unexpected coding errors.

Create WordPress Staging Environment using cPanel Control Panel

In fact, if you are using the managed WordPress hosting, you can be worry-free, for many of these web hosts offer the staging feature by default. However, if your hosting solution is unmanaged, you can create in a manual manner with your control panel. In the following, we just take the widely-used cPanel control panel as an example.

Step 1 – Create a Staging Sub-Domain

With the sub-domain, you can run a staging site of your main domain in a totally separate folder, which comes with the identical contents and does not affect your main files and databases.

To do this, you simply need to click the Sub-Domains icon in your control panel. In the next page, enter the sub-domain name, main domain name and the document root. As you are creating the staging site, we highly recommend you fill out the blanks as the following screenshot displays. Then, click the Create button.

Create a Staging Sub-Domain

Step 2 – Create the FTP Account for the Staging Site

The next step is to create an exclusive FTP account for your staging website, with which you can only access the staging directory, eliminating the possibility of changing your live site accidentally.

Here, you need to click the icon of FTP Accounts in the Files section, and decide the login username, password and directory in the next screen. Note that the directory needs to be matching the document root of your sub-domain. After that, hit the Create FTP Account button.

Create the FTP Account

Step 3 – Copy and Paste the Data from Live Site to Staging Site

Now, you should copy all the data from your WordPress site to your newly created staging site, so that you can start the test in a staging environment with the same contents of the live site.

To do this, we highly recommend you to use the phpMyAdmin. After clicking its icon in your control panel and logging in successfully, you should click the database of your currently live WordPress site. In the next screen, simply hit the Operation tab in the navigation and find the section of copying database.

phpMyAdmin Operation

Now, you need to pay attention to the following steps.

  • Enter the database name for your staging site. If you haven’t created one, do not forget to click the 4th box that allows you to create the database before copying the data.
  • Choose to copy both data and website structure.
  • As for the remaining settings, it is recommended to keep them unchanging.
  • Click the Go button.

After that, you can find your staging database listed in the left-hand sidebar. Then, you need to click it and hit the SQL tab in the phpMyAdmin menu bar. The aim for this is to run some SQL queries to ensure that the database works fine for your staging site.

Here, you need to clear the original SQL quires and enter the new lines that are listed in the below screenshot.

Run SQL Quires

Do not forget to replace the values based on your real situations.

  • Original URL is the URL of your live site.
  • New URL is the URL for your staging site.
  • wp_ is the prefix of your database name. If your prefix is a custom one, you need to make the changes for wp_posts, wp_postmeta and wp_options.

Upon the completion, you need to click the Go button to run the queries. This tool will show you a confirmation message when everything is finished.

Step 4 – Copy and Paste the Files from Live Site to Staging Site

After copying the database, it is time for all the files. Here, you have two options.

  • If your main site is not a large one that do not have too many files, you can use the FTP client. For this, you can download all the files to your local desktop using the FTP of your live site, and then, upload these files to your staging site via the new FTP client created in the step 2.
  • In contrary, you’d better choose the File Manager in your cPanel, with which you can copy and paste all the files from the server directly, making the process much faster.

Here, we just take the second option as an example. After clicking the File Manager icon from the Files tab, you need to open the folder of “public_html”. Then, you can find an inner folder named as wp-content, which includes all the files you should copy for your plugins, themes and uploads.

WP-Content Files

Now, you should choose the files for Plugins, Themes and Uploads in one time, right click your mouse and hit the Copy button. Then, you can be presented with a pop-up window that requires you to enter the path that you want to paste these files to. Here, you should enter the path of your staging site. In our example, it is “/public_html/staging/wp-content”.

Copy Files

After clicking the Copy Files button, you can install a new piece of WordPress for your staging site and get it connected with your staging database.

Step 5 – Finish Some Minor Settings

Last but not the least, you need to carry out some minor configurations to finish the creation of WordPress staging environment.

  • Check whether all your media files have been copied successfully. You can figure out this by logging in the admin panel of the staging site and checking the Media section.
  • Make sure that all the SEO related plugins are disabled, especially those for the XML sitemap. This can prevent search engines from crawling your staging environment.
  • As this site is only for testing, you need to restrict any other reader from accessing your site.
  • Set up the permalinks to avoid the 404 error.
  • Have a look at your staging site to figure out whether it can work properly and whether it is 100% identical to your live site.