7

How to Copy Your WordPress Site to a Subdomain for Safe Testing

 2 years ago
source link: https://www.makeuseof.com/copy-wordpress-site-subdomain-safe-testing/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to Copy Your WordPress Site to a Subdomain for Safe Testing

By David Abraham

Published 16 hours ago

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:

Step 1: Create a Subdomain

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.

Screenshot of domains section in cPanel

In the resulting interface, enter the name you have chosen for your subdomain and click create.

Step 2: Create and Download a Copy of Your Website

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.

Screenshot of filezila setup

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.

Screenshot of cPanel settings to 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.

Step 3: Export the Database

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".

Create-new-database

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.

Database-export

Once this is done, the next step will be to edit the database credentials in the wp-config.php file.

wp-config-database-name

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.

Step 4: Change URLs With 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.

Migrate-DB-Interface

Click on Migrate and scroll down to the section labeled Tools For This Site.

Migrate-DB

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.

Two More Ways to Clone Your Website to a Subdomain for Staging

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:

Alternative 1: Creating a Staging Website in cPanel

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.

Alternative 2: Using a WordPress Plugin to Create a Staging Website

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.

Get Started With Cloning Your WordPress Website

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.

About The Author

611337116f304-David%20Prof%20Pic%20B.png?fit=crop&w=100&h=100

David Abraham (10 Articles Published)

David is a WordPress lover who is passionate about helping small businesses grow!

More From David Abraham

Subscribe to our newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!

Click here to subscribe

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK