cPanel Logo Reflection

How to clone a website in cPanel

Would you like to clone any website in cPanel? There is a pretty fool-proof way to clone a website and change the references to URLs, paths and database details. There isn’t one perfect catch-all method, but you can cover most bases using this short guide.

In this guide we’ll use web1 and web2 as the usernames and web1.yourdomain.com and web2.yourdomain.com as their respective URLs. Note that if the source website is live, it will be offline for the time it takes to restore the data from its backup.

Create a backup of the source website

Run this command in shell:

This will place a file named cpmove-web1.tar.gz or similar into the /home directory.

Modify the username and URL

In WHM go to Modify Account, select the source username: web1 and edit the main details to use the new URL and usernames: web2 and web2.yourdomain.com.

This is your cloned website. It is now live at the new URL, but if there is a database or a configuration, this will need to be updated to reflect its new location.

Restore the source

Get the source website back up and running by restoring the backup you’ve just created.

Update the configuration files

For modern websites, you’ll need to update its configuration to use the newly cloned database and perhaps the paths and URLs. You can search and replace text within files using this command.

This will update the Magento configuration file. If you have WordPress, this command will update its configuration:

Change the location of the file as needed. Searching for the old database name will be a good place to start if you’re unsure about which file to change:

This will give a list of files containing the previous database name. Change it to the source path or source URL for more files. It is best to ignore any log file results, press Ctrl C if you’re getting deluged by results.

Update the database

I use a really cool database search and replace script that I found to change the URL of WordPress websites. It has a CLI version that will connect to any database and change its values, including serialised data.

Change the details here to reflect your setup.

Remove temporary files and empty the cache

If you’re unsure about this part, probably backup these files before deleting them.

This will clear temporary Magento files. If you have WordPress and use a cache, this will clear the cache files:

If you’re cloning multiple times, you can string a list of commands to perform the clone with minimal human input.

If you spot anything that I’ve missed, please drop me a comment here.

Leave a Reply

Your email address will not be published. Required fields are marked *