Do you need help to create a WordPress staging site with cPanel?
A staging site (also known as a test site or development site) is a duplicate of your live site. It allows you to make changes privately without disrupting your live site. This is a very useful tool to learn if you are:
- testing plugins for compatibility,
- testing if your WordPress Theme is compatible with new WordPress updates,
- implementing major features and content on top of your current site,
- fixing glitches, bugs, or security vulnerabilities, and
- building a new site, among many other reasons.
If your WordPress site is producing income or generating high traffic, learning how to create a staging site with cPanel helps minimise disruptions. For example, if something goes wrong on the staging site, it is as easy as reverting the change, or deleting everything, and duplicating your live site again very quickly.
In this tutorial, you will learn how to create a WordPress staging site with cPanel manually, essentially for free. Fortunately, there are plugins and services that you can use for convenience which may incur a fee, but if you are on a budget or just curious, then let’s get started!
Step 1: Create a subdomain
Login to your site cPanel and create a subdomain. Everyone’s cPanel will look different and would be normally found in Domain > Subdomain.
Make a note of where the staging folder sits in your directory. For example, the staging folder in this tutorial sits in: alexthedigitalproducer.com/public-html/staging (yours will be different).
Step 2: Duplicate the live WordPress site to the staging site
In cPanel Home, access File Manager and navigate to your ‘public-html’ folder. Copy everything and paste them into the staging folder.
Remember, if the ‘staging folder’ also sits in ‘public-html’, do not duplicate that folder.
After copying, go into the staging folder > find a file called ‘wp-config.php’ > right-click to View. Approximately 30 lines down, make a note of your database name and database username. This will be important throughout this tutorial.
Step 3: Duplicate the live WordPress site database
WordPress not only contains pages to display your site, but also a database that manages and pushes important data to ensure your site is looking and functioning correctly.
Exit File Manager > back to cPanel home > navigate to phpMyAdmin.
- On the left navigation bar, click on your live site’s database name.
- On the right panel, click Operations.
- Go to ‘Copy Database to’ subpanel and give your staging database a new name. For example, this tutorial will name the staging database as ‘atdp_staging’.
- Click Go to begin the duplication process. It is important to wait and not disrupt this process or else you may create a corrupted database without knowing.
Step 4: Configuring the staging database
- On the left navigation bar, click into the newly duplicated staging database.
- Navigate to ‘options’ table.
Note: Every WordPress database installation typically has their tables prefixed with something. For example: ‘wp_options’. Everyone’s table will look different, but most of the time, there will be a ‘[prefix name] _options’ table.
- Navigate to ‘siteurl’ and click Edit. Change the URL to the staging URL, then click Go.
Tip: If you cannot find ‘siteurl’ in the table, go to Filter rows (*) and type it in.
- Repeat the same process for ‘home’ by changing the URL to the staging URL, then click Go.
- Exit phpMyAdmin and return to cPanel Home.
Step 5: Assigning the staging database to the database username
Previously in Step 2, remember you were asked to record the database username?
At cPanel Home, go to MySQL Databases > Add User to Database (heading)
Then, in the ‘User’ panel, refer to your notes from staging ‘wp-config.php’ database username. In the ‘Database’ panel, add the staging database name that was duplicated from phpMyAdmin.
Then click Add.
You’ll be directed to another page to provide permissions to the user (i.e. webmaster/administrator). Tick ‘All Privileges’ > Make Changes. Then exit MySQL Databases and go back to cPanel Home.
Step 6: Configuring ‘staging/wp-config.php’ file
Open File Manager > navigate to staging folder > right click on ‘wp-config.php’ file > click Edit.
You’ll be prompted with a warning. Create a backup of wp-config.php (in case you need to revert), then click Edit once more.
Approximately 30 lines down, change the database name to the one created from phpMyAdmin. Click Save Changes > Close
Exit File Manager and log out of cPanel.
Step 7: Finalising the staging site
We are almost there, well done for making it this far.
Go to your web browser > type in the staging site URL + wp-admin to access the backend. For example, https://www.alexthedigitalproducer.com/staging/wp-admin
Tip: The username and password are the same as the live site.
In Common Settings (heading), check Post Name > then Save Changes. This is important because the permalinks are still referencing to the live site. Updating this will reference to the staging site permalinks.
Finished…but wait!
That’s the end of the tutorial! You now have the tools to create a WordPress staging site with cPanel and you can now safely make edits on the staging site without disrupting your live site. But wait! What happens when you finish editing the staging site and want to migrate everything to live? You will find out in the following tutorial set to be released next week - watch this space.
If you found this tutorial useful, please leave a comment below and share this blog. Let us know if you have topics you would like us to cover in the future.
Happy staging!
Brilliant tutorial.
Every step included to get a staging site up and running.
Can’t wait for the next one to work out how to push from staging to live in the cpanel
Thanks for the feedback! We have the next part of the tutorial ready 🙂
Here is the link: https://www.ironbarkmarketing.com/how-to-move-a-wordpress-staging-site-to-live-using-cpanel/
Brilliant – just what I needed! This tutorial saved me a ton of time in setting up my staging site, and Alex’s quick response to my question was a big help. Now to redesign my organization’s web presence and use Ironbark’s go-live tutorial to get it on the air!
Anytime, Bob! Thank you so much for the feedback 🙂
This is the second time I followed this guide to setup a staging installation. The first time it had worked flawlessly. This time around, though I was experiencing the following issue: whenever I entered my correct login credentials to login to the staging environment, I was being redirected to the login screen (chrome) or to the wp-admin of the production installation (firefox). I started to type this in present tense to ask for assistance, but then I thought of checking my .htaccess file, to see what was copied over. I had to deactivate the cache settings, by setting the define( \\\\\\\”wp-cache\\\\\\\”, true ); to define( \\\\\\\”wp-cache\\\\\\\”, false ); I also set to false the following three settings related to the
\\\\\\\”Really Simple SSL\\\\\\\” plugin:
@ini_set(\\\\\\\’session.cookie_httponly\\\\\\\’, false);
@ini_set(\\\\\\\’session.cookie_secure\\\\\\\’, false);
@ini_set(\\\\\\\’session.use_only_cookies\\\\\\\’, false);
Lastly I had to explicitly define the \\\\\\\”wp_home\\\\\\\” and \\\\\\\”wp_siteurl\\\\\\\” settings, despite having addressed that directly on the database on step 4.
After saving and refreshing the wp-admin of the staging site I was able to login successfully on the first try.
I am leaving this info here for potential future help of anyone facing similar issues like I did.
Ehm… Also it would be helpful to not convert all input to capitals, as to avoid outputs.
Thank you for sharing your experience using this tutorial. I am glad it worked out for you in the end 🙂
THanks for this excellent tutorial alex. It worked perfectly for me and i really appreciated your clear, easy-to-follow instructions.
just one minor amendment: I didn’t need to complete the final step, and in my wordpress installation those settings are found under settings > permalinks.
Cheers!
I have completed all the steps but when at step 7, i enter my staging site url it takes me to the live site and says 404 not found. CAn you please help???
Hello there! I am going to assume that you followed the instructions correctly, and the scenario I can only think of that may apply to you is you may have changed your /wp-admin URL on your main site to something else. For example… “/wplgn”. You may have made this change at a server level or using a plugin. Let us know if this helps with your troubleshooting 🙂
I am really appreciative of this step-by-step guide. I followed everything carefully to create a test site and get to \’404 Page Not Found\’ like vin above. do i need to install wp in the sub-domain?
thank you very kindly… derek
Hello! My apologies for the late reply. No, you don’t need to install WP in the subdomain as part of the tutorial duplicates the database and files (including WP) to your designated staging site. For starters, check if your primary site wp-admin url has changed. This was either done at a server level or with a plugin. Revert it back to default and try again. Also, check if you have any web / server security that may have prevented you from creating or accessing your staging site. Thanks for dropping by.