This guide explains how to duplicate a WordPress website or migrate it between domains — either within the same server, across servers, or between different hosting panels.
📄 Scope of This Guide
This wiki applies to:
- 🧳 Migrating between different domains on the same server.
- 🔁 Moving a site from one cPanel account to another.
- 🌐 Changing a domain name while keeping the same website content.
✅ Migration steps are the same across control panels — the only variation is in the document root and panel interface.
📂 Document Root Path by Control Panel
| Control Panel | Document Root Path |
| ———————————| ———————————————————————–|
| cPanel | /home/username/public_html/ |
| CyberPanel | /home/domain.tld/public_html/ |
| HestiaCP | /home/user/web/domain.tld/public_html/ |
| Plesk | /var/www/vhosts/domain.tld/httpdocs/ |
|———————————————————————————————————–|
⚠️ Note: Always verify the actual path, as it may vary depending on the hosting environment.
Pre-Migration Checklist
Before beginning the migration:
- ✅ Ensure the source domain is resolving and loading properly.
- 💾 Confirm you have enough disk space on both the source and destination servers.
- 🔐 Keep SSH or control panel credentials ready (WHM, cPanel, CyberPanel, etc.).
🌐 Check if the Source Domain is Working
Open your web browser and visit:
http://domain1.com
✅ If the page loads correctly, you’re good to proceed.
❌ If not, resolve DNS or server issues first.
🛠️ Locate the Website Document Root (Source)
Log into your server via SSH or WHM Terminal and run:
grep domain.com /etc/userdatadomains
🔎 This will show the cPanel username associated with the domain.
📁 The typical path for cPanel users is:
/home/username/public_html/
Let’s Begin the Migration
Access the Website Directory
Navigate into the website’s directory:
cd /home/username/public_html/
📊Check Server and Website Disk Usage
To check how much disk space your files are using:
du -sch *
To check overall disk space available:
df -Th
⚠️ Make sure you have enough free space for the backup.
🔍Identify the MySQL Database
Run this command to view database credentials:
cat wp-config.php | grep DB
This shows:
define( ‘DB_NAME’, ‘example_db’ );
define( ‘DB_USER’, ‘example_user’ );
define( ‘DB_PASSWORD’, ‘example_pass’ );
🗃️Backup the MySQL Database
Use mysqldump to export the database and Use one of the following commands:
mysqldump -u db_user -p db_name > database.sql
Or:
mysqldump db_name > database.sql
Or with transaction-safe flag (recommended for live sites):
mysqldump --single-transaction db_name > database.sql
✅ This creates a file named database.sql with your full DB.
💡 You can also export the database using phpMyAdmin if you prefer a GUI.
Take a Full Backup of the Website Files
From the site’s root directory:
tar -czvf fullbackup.tar.gz *
📦 This archives all website files in the current directory.
Note: Check .htaccess (e.g., vim .htaccess) and if it’s customized, consider backing it up separately:
tar -czvf htaccess-backup.tar.gz .htaccess
Optional: Exclude Unwanted Files from the Backup
To avoid backing up unnecessary data (like plugin backups):
tar -czvf fullbackup.tar.gz --exclude=wp-content/ai1wm-backups --exclude=wp-content/updraft *
🧹 This skips large backup folders in the archive.
🎯 You can manually remove files using:
rm -rf unwanted_folder_or_file
Examples:
Remove old backup plugin folders
Delete large cache directories
Once the backup is complete, the file will be named `fullbackup.tar.gz`.
Fix File Permissions (for download or transfer)
If you plan to migrate the backup to another server, then correct the permissions and ownership. Once done, you can download it from the destination server.
chown username:group fullbackup.tar.gz chmod 644 fullbackup.tar.gz
🌱 Create the New Domain on the Same or Another Server
Once created, access the newly created domain document root:
cd /home/newusername/public_html
Copy the backup:
If it’s the same server copy the backup file
cp /home/username/public_html/fullbackup.tar.gz /home/newusername/public_html
If it’s a remote server, download it using:
wget https://domain.tld/fullbackup.tar.gz
🔁 Alternatively, use scp to copy via SSH:
scp user@oldserver:/path/to/fullbackup.tar.gz .
Extract the backup file
Move to new domain document root and Unpack the archive:
tar -xvf fullbackup.tar.gz
🗂 This will extract all files into the current directory.
🔧 Create the New Database
If using cPanel, create the database via the control panel. Otherwise, use CLI:
mysql -u root -p CREATE DATABASE newdb; GRANT ALL PRIVILEGES ON newdb.* TO 'newuser'@'localhost' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
Once done, edit the `wp-config.php` with the new database details:
vim wp-config.php
Update:
DB_NAME
DB_USER
DB_PASSWORD
🧰 Import the Database
Import using:
mysql db_name < database.sql
Or:
mysql -u username -p dbname < database.sql
This loads the content from the backup into the new DB.
🔄 Update the Site URL (If Domain Changed)
If you’re changing domains, update URLs in the database.
Option 1: Using sed command:
cp database.sql database1.sql sed -i 's/old_domain/new_domain/g' database1.sql
mysql -u username -p dbname < database1.sql
Option 2: Search-Replace Script (best for complex data)
git clone https://github.com/interconnectit/Search-Replace-DB.git chown -R username:username Search-Replace-DB
Open in browser:
http://domain/Search-Replace-DB
🔁 Replace all old URLs with the new domain.
Test the Website
Open the new site in browser:
http://newdomain.com
🔎 Test pages, media, login, forms, admin panel.
Cleanup
After confirming everything works, remove sensitive files:
rm -f database.sql fullbackup.tar.gz
Also remove Search-Replace-DB tool:
rm -rf Search-Replace-DB
🎉 Migration Complete!
You’ve successfully duplicated or migrated your WordPress site.