How To Clone A Website In cPanel® | cPanel Blog

How To Clone A Website In cPanel® | cPanel Blog

You might also like

A cloned is a perfect duplicate of a site hosted on your server. It has the same files, and the contents of its database are identical to the original. The only difference is that the cloned site is hosted at another domain or directory. 

There are many reasons you might want to clone websites on your server. Because the copies are identical to an existing website, cloning helps deploy testing and staging sites. It’s also a quick way to set up a new site using the old one as a baseline configuration. Site owners often use cloned sites to give designers and developers access to a working environment that behaves like the live environment. 

Cloning can be done on the command line, but it’s time-consuming, and it’s easy to make a mistake. cPanel & WHM automates the more error-prone steps, so you can quickly clone sites based on content management systems and eCommerce applications. 

This article looks at two strategies for cloning sites on your cPanel-managed server:

  1. A generic cloning process that works for most CMS or eCommerce sites, although we will use as an example. 
  2. A WordPress-specific process within WordPress Toolkit, which makes cloning a one-click task by automating copying and site configuration. 

We’ll start with the quickest and most convenient way to clone a WordPress site in WordPress Toolkit before exploring a more manual process that will also work with other content management systems. 

Cloning a WordPress Site with WordPress Toolkit

Open WordPress Toolkit and expand the detail view for the site you would like to clone. Click the Clone tool in the site’s dashboard. 

When the clone tool opens, select a subdomain and a path to clone the site to. If they don’t exist, WordPress Toolkit creates them for you. When you’re finished, click Start at the bottom of the page. 

WordPress Toolkit automatically copies the site, creates a new database and database user, configures the site to use the database, and creates a new subdomain if necessary. Once it’s done, you access the cloned site as usual. 

You can learn more about WordPress Toolkit’s sophisticated cloning and copying features in How to Deploy a WordPress Staging Site With cPanel or explore more of WordPress Toolkit’s many WordPress management features

How to Manually Clone a Website with cPanel

Content management systems—including WordPress, , and —are composed of two main asset types. The first is PHP code files and static files such as images, JavaScript files, and CSS. The second is information stored in the site’s database—page content, configuration settings, user information, and so on. 

To clone a site, we have to copy both, so the process looks like this:

  1. Create a new folder and copy the site’s files into it. 
  2. Export the original site’s database, create a new database for the clone, and import the data into it. 
  3. Configure the clone to work with the new database. 

Let’s see how we’d use this process to clone a WordPress site.  We’re going to focus on cloning a site into a new directory rather than a subdomain. 

Create a Folder and Copy the Site’s Files

We can create a folder for the site’s clone and copy the files in File Manager, which you can open from the Files section of cPanel’s main page menu.

  1. Select the directory containing the WordPress site you want to clone. 
  2. Click Copy in the toolbar and enter a name for the new directory. To keep things simple, we’ll clone the site into a directory under public_html so that you can access it from a URL such as “example.com/wordpress_two.” 

File Manager copies the directory and all of its contents, giving you an exact duplicate of the original site’s files. 

Clone the Site’s Database

Cloning the database is a little more complicated than copying files, but it’s straightforward with cPanel’s MySQL tools. 

First, we create a new database. 

  • Open MySQL Databases, which you’ll find under Databases the main page menu. 
  • Enter a name for the new database under Create New Database and click the Create Database button. 

Next, we export the original database.  We’ll use phpMyAdmin, which is also under Databases in the cPanel menu. 

  1. Select the original database in the sidebar.
  2. Select the Export tab and make sure the Quick export method is selected. The custom method lets you change database export options, but we’ll stick with the defaults. 
  3. Click Go.  

This “dumps” the database, downloading an SQL file to your local machine with the information needed to recreate the original site’s database. That’s what we’re going to do next, also using phpMyAdmin. 

  1. Select the new database (the one we created in the previous section).
  2. Click the Import tab. 
  3. In the File to import section, click Choose File and browse to the SQL file you just downloaded. 
  4. Click the Go button at the bottom of the page.

The last step in this section is to give the database a user with a password. You can use an existing database user, but we’ll add a new user and give them a unique password. 

In cPanel, navigate to the MySQL Databases page. Scroll to the Add New User section. 

  1. Under Add New User, enter a username and a strong password. 
  2. Click Create User, and then return to the MySQL Databases page.
  3. Under Add User to Database, select the new user and the database we created in a previous section. 
  4. Click Add, select “All Privileges” on the next page, and confirm the changes.

We now have the files and the database copied, but our cloned WordPress site is still configured to use the original site’s database. The next task is to configure the clone to use its own database.

Edit the Cloned Site’s Database and URL Configuration

This step is WordPress-specific, but you will have to do something similar for other content management systems. 

  1. Open File Manager and select the new site’s directory. 
  2. Select the wpconfig.php file. 
  3. Click Edit in the toolbar. 

We need to edit several fields in the MySQL settings section of wpconfig.php so that WordPress can access and authenticate with the new database. 

  1. Enter the new database name in the DB_NAME field.
  2. Enter the user we just created in the DB_USER field.
  3. Enter the user’s password in DB_PASSWORD. 

While we have wp-config.php open, we can also tell WordPress about its new URL. There are various ways to do this, but the quickest is to add the following lines, with appropriate changes, to the bottom of the file. 

<!-- wp:paragraph -->
<p>define( 'WP_HOME', 'http://example.com/wordpress_two' );</p>
<!-- /wp:paragraph --> <!-- wp:paragraph -->
<p>define( 'WP_SITEURL', 'http://example.com/wordpress_two' );</p>
<!-- /wp:paragraph -->

Don’t forget to click Save Changes when you’re finished. 

All being well, you should be able to load your cloned site at http://your_domain.com/your_subdirectory. If you’ve followed the examples, that will be something like http://example.com/wordpress_two. 

As always, if you have any feedback or comments, please let us know. We are here to help in the best ways we can. You’ll find us on Discord, the cPanel forums, and Reddit. You’ll find us on Discord, the cPanel forums, and Reddit. Be sure to also follow us on Facebook, Instagram, and Twitter.

Random Articles

Web Design