Client Login

How to create a WordPress staging site with cPanel

What Is a WordPress Staging Site ?

A staging site is a cloned copy of a production site that is used to test changes before making them live. In simpler terms, it is a copy of your website where you can make changes that do not alter your live website until you deploy them. Staging sites help you catch errors, so you do not damage your website. Moreover, it also helps to avoid downtime and bad user experience. It contains the same data and files, but it is not publicly accessible and usually hosted on a different subdomain. In this article, we will explain what you need to know about WordPress staging sites.

Why do you Need a Staging Site ?

If a business depends on its WordPress site or WooCommerce store, editing the live production installation is risky. WordPress staging sites also called development sites or testing sites, are safe alternatives. Ideally, any edit more complicated than publishing a post is thoroughly tested before it goes live.

Cases for staging sites are:
Testing new landing pages to ensure each component works as expected before potential customers visit.
Checking updates for compatibility issues
Creating a new theme or modifying the current theme.
Modifying the site’s code to add new features.
Staging sites are also useful when you want to allow developers and designers to work on your site but don’t want to give them access to the production
installation.

Now that you know the benefits of staging a website before production, let’s look at how this task can be accomplished.

WordPress is one of the most popular content management systems (CMS). However, it requires regular updates to ensure full functionality and optimal performance. When performing updates, it is always recommended to have a separate clone of the site in a staging environment to test the compatibility of patches and updates with the site and plugins.

Here are the steps for staging the cPanel site.

Step 1: Create a Subdomain in cPanel

  • To create a subdomain in cPanel, login to Verpex cPanel.
  • Click Subdomains in the Domains section.
  • Give your subdomain a name (e.g. test), then click the Create button to add your subdomain, which you can use to import your live WordPress site. Note the location of the staging folder in your directory. The subdomain is where you will access your new staging environment.

Using File Manager
Manually create a staging site using File Manager:
Login to your cPanel, and click Advanced
files. In the public_html folder
Navigate to File Manager, under the public_html folder, download the entire root folder of the website for which you want to create a staging site.

Step 2: Copy the Database Using phpMyAdmin

Your WordPress site will have at least one associated database. The database name can be found in the wp-config.php file in your public_html folder. Once you know the database name, access phpMyAdmin in the Databases section of cPanel.

  • Go to phpMyAdmin
  • Click on your database name(the database name copied from wp-config.php).
  • Choose the Quick export and SQL format options.
  • Click Go, this option downloads a copy of the site’s database on your computer.

Step 3: Create a Database User and Assign it to a Database in cPanel

  • A new database that will act as a clone of the live one has to be created.
  • To create a new database, click MySQL Databases in the Databases section of cPanel.
  • Scroll down to the MySQL Users section, and click Create a database user
  • Enter the username, and password.
  • Once the user has been created, you need to add the User to the database
  • Scroll down to the Add User To Database section, select the newly created database and click Add.
  • Check the box next to All Privileges and click Make Changes.
    You now have two databases listed on the left side menu in your phpMyAdmin
  • Click the new database, then click Import.
  • Click Choose File to upload the .sql file which is the backup of the live website’s database into the new database.
  • After completing all necessary selections, click Go to finish the database import.
    Depending on the size of the uploaded file, it might take from a few minutes to a few hours. After the import is complete, you have two databases with the same database tables.
  • After cloning the database, you need to modify the cPanel staging site’s URLs.
    Do so in phpMyAdmin, click on the wp_options table, and edit the home and site URL options. Click Edit for each individual option to update the URLs.

Step 4: Copy Website Files in File Manager

The next step is to copy the files now that the database and user have been set up.. You can do this through file transfer protocol (FTP) or through cPanel's File Manager.

  • Log into cPanel, click File Manager
  • Locate and open the public_html folder
  • Click Select All
  • Click Copy.
  • The interface prompts you to set a destination for the cloned files. Enter the directory where your new subdomain is hosted. If you do not know which directory it is, go to the home screen and click Subdomains in the Domains section.

Once the files have been copied, you will need to type in the new database information: database name, database user, and password.

  • Go to the File Manager window.
  • Right-click on the wp-config.php file, and select Edit.
  • In the Database settings section, modify the wp-config.php file with the correct database credentials. .

// Database settings - You can get this info from your web host //
/* The name of the database for WordPress /
define( 'DB_NAME', 'budd_testing' );

/* Database username /
define( 'DB_USER', 'budd_testing' );

/* Database password /
define( 'DB_PASSWORD', '<database_password>' );

/* Database hostname /
define( 'DB_HOST', 'localhost' );

/* Database charset to use in creating database tables. /
define( 'DB_CHARSET', 'utf8mb4' );

/* The database collate type. Don't change this if in doubt. /
define( 'DB_COLLATE', '' );

  • After adding the correct credentials, click Save Changes.

Step 5: Create A Record for the Subdomain

An A record needs to be added to your domain name system(DNS) provider to enable you to use the cPanel staging site. The A record has to be pointed to the IP address listed in the General Information section in cPanel as a Shared IP Address. Once the DNS propagation is complete, your new cPanel staging site will be accessible using your chosen subdomain. However, to avoid potential problems with links in the database, replace them to match the subdomain of the staging website.

Instead of manually checking the directories (which can take hours), the easiest way to replace them is with a plugin, such as Better Search Replace. With the plugin installed, you can search and replace all instances of the old domain with the new one.

A WordPress staging site has its advantages and disadvantages:

Advantages
Risk-free environment: A safer environment to tweak your site or try out major updates without risking the live website functionality.
Early error prevention: Helps debug WordPress to discover critical issues and system crashes before the site goes live.
Flexible configuration: It can be configured locally or online, depending on your preferences.
The best possible output: It allows you to create a better site since you can test everything thoroughly before launching it.

Disadvantages

For beginners who have yet to learn WordPress, setting up a staging site can seem like a challenge at first. Creating a WordPress staging site online may include additional plugin or hosting costs. You will need to take some time to test the changes on the WordPress staging site and repeat the same changes on the live version of the site.

Conclusion

Due to frequent security threats and updates to WordPress themes, plugins and core files, staging sites are necessary. Knowing how to create a staging site in a cPanel is straightforward and easier than undoing changes that might break a production site. Additionally, our support team is available around the clock to assist you with cPanel functionality.

Expert Tip
Go through all the possible use cases with the changes you made. Only after you find no issues with them, then push the changes to safe production.