How to Create a Staging Site in cPanel

Posted on by Amy Myers
Reading Time: 6 minutes

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

This tutorial walks through how to create a staging site in a cPanel server. The cPanel staging site is a clone of the live site on the same machine, using a different domain as its site URL. This staging environment is separate from the live site. Here are the steps for cPanel site staging.

Requirements

  • A Linux-based server running cPanel.
  • At least one live website already set up on the server in cPanel.
  • No cPanel staging site set up for the domain.
Note:
Best practice is to make a fresh backup of your server before making any changes.

How to Create a Staging Site in cPanel

Step 1: Create a Subdomain in cPanel

To create a subdomain in cPanel, first log in to cPanel. In the Domains section, click Subdomains.

The interface prompts you to enter the prefix for your new subdomain. Once entered, click Create.

Once created, your new subdomain appears in the list under the Subdomains section.

Step 2: Copy Database Using phpMyAdmin

Your WordPress site will have at least one database associated with it. The name of the database is in the wp-config.php file, usually in the document root of the site. On cPanel servers, sites’ document roots will be in the /home/user/public_html directory. Once you know the name of the database, access phpMyAdmin in the Databases section of cPanel.

Once you’re in phpMyAdmin, click the name of your database in the far left column. For this tutorial, stick with the Quick export and SQL format options. Once selected, click Go.

This option downloads a text file with the .sql extension to your local machine. The file serves as the backup of your site’s database.

Create a new database that will act as a clone of the live one. You can do so by clicking MySQL Databases in the Databases section of cPanel.

Choose a name for the new database and click Create Database.

Navigating back to phpMyAdmin, you now have two databases listed in the menu on the left side. Click the name of the new database, then click Import. To upload the .sql file (the backup of the live website’s database) into the new database, click Choose File.

Once you complete all the necessary selections, click Go to finish the database import. Depending on the size of the uploaded file, it might take anywhere from a few minutes to a few hours.

Once the import is complete, you have two databases with the same database tables.

After cloning the database, you need to change the cPanel staging site’s URLs. Do so in phpMyAdmin, by clicking on the wpnv_options table, and editing the home and siteurl options. Click Edit by each individual option to update the URLs.

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

To use the new database without causing issues on the live site, create a new MySQL user. Create a database user by clicking MySQL Databases in the Databases section and scrolling down to the MySQL Users section. Click Create User once completed entering the username, password, and confirmed password.

After creating the user, click the Go Back option to return to the MySQL Databases screen. Scroll back down to the Add User To Database section. Select the newly created database and click Add.

This selection brings up a list of privileges the user needs on this database. For a fully functioning site, select the checkbox next to All Privileges and click Make Changes.

Step 4: Copy Website Files in File Manager

With a database and user set up, you must copy the site files. You can do this via file transfer protocol (FTP) or via cPanel's integrated File Manager. This tutorial uses cPanel’s integrated File Manager.
From the main menu, click File Manager in the Files section of cPanel.

In the File Manager window, locate the public_html file. Click Select All to select all files in the folder. Click Copy.

The interface prompts you to define a destination for the cloned files. Enter the directory in which your new subdomain is hosted. If you are unsure which directory it is, navigate to the home screen and click Subdomains under the Domains section.

Once the files are copied, navigate to the File Manager window. Right-click on the wp-config.php file, and select Edit.

Under the Database settings section, modify the wp-config.php file with correct database credentials.

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

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

/** 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', '' );

Once you’ve added the correct credentials, click Save Changes.

Step 5: Create A Record for the Subdomain

To use the cPanel staging site, add an A record for it. You need to add it on the side of your domain name system (DNS) provider. Point the A record to the IP address listed in the General Information section in cPanel as a Shared IP Address.

Once the DNS propagation finishes, your new cPanel staging site will be accessible using your chosen subdomain. However, to avoid potential issues with links in the database, replace them to match the subdomain of the staging website.

Rather than going through the directories manually (which could take hours), the easiest way to replace them is with a plugin, such as Better Search Replace. Once installed and activated, you can search for all instances of your old domain and replace them with your new domain. 

Wrapping Up

Due to the frequent security threats and upgrades happening 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 reverting changes that might break a production site.

Ready to get started hosting a staging site with cPanel? Contact our sales team for more information on our managed hosting options. In addition, our support team is available around the clock for assistance with cPanel functionality.

About the Author: Amy Myers

Amy is a Linux support technician with Liquid Web and Nexcess, with expertise in customer service. She considers expanding upon and sharing knowledge as one of life's top priorities. She is an avid technology and art fan.

Latest Articles

How to Install MySQL on Windows Server 2019

Read Article

How to Set Up a Cron Job in cPanel

Read Article

What Is Puppet Software and How Do You Use It?

Read Article

Accessing Man Pages on Ubuntu 16.04 LTS

Read Article

What is VMware Fusion?

Read Article