How to Clone a Website in cPanel


A cloned website 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 cPanel 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.

How to Manually Clone a Website with cPanel

Content management systems—including WordPress, Joomla, and Drupal—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."

clone site files

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.

create database

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.

Export database

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.

import database

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.

Add new database user

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 wp-config.php file.
  3. Click Edit in the toolbar.

change WordPress database

We need to edit several fields in the MySQL settings section of wp-config.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.

Edit wp-config.php

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.

  • 1 A felhasználók hasznosnak találták ezt
Hasznosnak találta ezt a választ?

Related Articles

Video: Create Email Address in cPanel

This video tutorial demonstrates how to create an email address using cPanel Shared Hosting...

Disabling mod_security in cPanel

Mod_security is an apache module that helps to protect your website from various attacks. It is...

Video: Setup Email Forwarder in cPanel

View our Step-by-Step Tutorial Video for Setting up an Email Forwarder in cPanel Shared Hosting.

Install an SSL Certificate Using the AutoInstaller Software in cPanel

This article will describe how to use AutoInstall to install an SSL certificate.The AutoInstall...

Video: Add MX Entry in cPanel

This video tutorial provides Step-by-Step instructions for adding an MX entry in cPanel Hosting...