To avoid messing up with the primary site, copy the site to a subdomain for all testing purposes. Here’s how.
Looking to build a new website, update an old one, or try out some new plugins? The best practice is to get started by using a staging website. This provides a safe environment for testing and experiments, and if anything goes wrong, you don't have to worry about your live website crashing or being out of service for a while.
The precise steps to take in creating a staging website may differ depending on the type of website. In this post, you will learn how to easily copy your WordPress site to a subdomain for safe staging. Here are the steps to follow:
You will need a subdomain where you can host your new staging websites. Hopefully, you already know what a subdomain is. Subdomains are free to create, and most hosting services allow you to create numerous ones. This makes creating your staging website at a subdomain a good solution.
To create a subdomain, head over into cPanel and navigate to Domains > Subdomains.
In the resulting interface, enter the name you have chosen for your subdomain and click create.
Once you have created a subdomain, you now have an address for your staging website. The next step in creating a staging version of your website will be to clone your existing website. This is easy to do using FTP. You'll need to download and install an FTP client, and we'll recommend that you use FileZilla for this as it's free and open-source.
Once installed, you'll need to connect your FTP client with your FTP server. To do this, you'll need your FTP account details, and these are usually provided by your hosting provider when you sign up for a new web hosting account.
The necessary fields are host, username, password, and port. You will see two panes in your FTP client. On the left will be the folders on your computer, and on the right will be your website's files.
Copy these files and save them to any folder on your computer.
You can also do this in cPanel. Navigate to Files > File Manager >Public_html. In the top right corner of the interface, click on settings. In the resulting popup, tick Show hidden files.
Select all the folders that appear, with the exception of cgi-bin, and click copy from the top menu, or right-click on the selected files and select copy. In the resulting popup, enter the name of the directory. This will be the name you chose for your subdomain.
The next step in cloning your WordPress website will be copying the database of your live website to the staging website. The database is where all of the content and data for a WordPress website is stored. You will need to create a new database for your staging website before you import the content from the database of your live website.
In cPanel, head over to Databases > MySQL Databases. In the resulting interface, enter a name for your new website. It can be anything, for example, "test".
Once this is done, head over to phpMyAdmin > databases. Here you will export the old database and import the content to the new one in a few simple steps.
In the left-hand panel, click on the old database and then export. The file will then be downloaded to your computer.
To upload it to your new database, simply click on the new database and then import. Search for and upload the database from your computer.
Once this is done, the next step will be to edit the database credentials in the wp-config.php file.
In the wp-config.php file, look for the line that says define( 'DB_NAME', …..);. Simply change the database name to the new one here. Once this is done, you're almost set.
The final step will be to change the URLs in the new database, to ensure that they all point to the new website instead of the old one.
You'll need to do this with a plugin. There are several plugins you can use to get the job done, however, we'll recommend WP Migrate DB.
To get started, install and activate the plugin from the WordPress plugin directory. Once this is done, click on Tools from the left-hand menu, and select Migrate DB.
Click on Migrate and scroll down to the section labeled Tools For This Site.
Select Custom Find & Replace. This will open up a dropdown interface with an option for Find and another for Replace.
In the space for Find, enter the name of your old website preceded by two forward slashes like this: //oldsite.com. In the space for Replace, do the same with the URL for your new site.
That's it! You should have a fully functional staging website to work with.
You don't always have to use the manual method to clone your website to a subdomain for staging. In fact, there are several different ways to set up a staging website. Two of the easier methods include using bespoke options provided by your hosting service, or using a plugin.
Here's a quick rundown of both alternatives:
If your hosting service uses cPanel, you can create a staging website with just a few clicks. To get started, first create a subdomain following the steps described in step one up above.
Once this is done, navigate to Software > WordPress Manager by Softaculous.
Click on the dropdown icon next to the name of your website, then click on staging, and then enter the subdomain you created.
That's it. If you prefer not to use this method or your hosting service doesn't use cPanel, you can try using a WordPress plugin.
There are several plugins that help with creating staging websites. We've talked about one already—Migrate DB. Migrate DB is an ideal solution for changing URLs, but to use its other features to create a staging website, you will need the premium version.
Alternatively, you can use one of several free staging plugins such as Duplicator, WP Stagecoach, UpDraft Clone, and so on.
Creating a staging website to build a website before taking it live, or to test out updates, new plugins, or any customizations, is always a good idea. We've shown you how to do this manually, as well as how to leverage your cPanel to create a staging website. We've also mentioned a few plugins that are useful for this.
If you're just getting started with building your website, one good practice might be to build it out in a local development environment first, so that you don't need to clone it subsequently.
Tired of using XAMPP? Try these local server management tools instead.
David is a WordPress lover who is passionate about helping small businesses grow!
Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!