Advanced WordPress Migration via SSH (Server-to-Server) Print

  • database import, ssh transfer, rsync wordpress, wp-cli search replace, wordpress migration
  • 0

Overview

Moving a WordPress site manually via SSH is the most efficient method for large websites. This process involves two main parts: moving the Files and moving the Database.


Step 1: Export the Database (Source Server)

Log into your Old Server via SSH. Navigate to your website root (usually public_html) and export the database.

# Export the database to a file
# Tip: Check your wp-config.php for these credentials
mysqldump -u DB_USER -p DB_NAME > database_backup.sql

Step 2: Transfer Files and Database (Destination Server)

Log into your New Server via SSH. We will use rsync to "pull" everything directly from the old server to the new one.

# Navigate to your new website directory
cd /var/www/vhosts/domain.com/public_html

# Pull all files from the old server
rsync -avzP root@OLD_SERVER_IP:/home/username/public_html/ .

Step 3: Create a New Database (Destination Server)

On your new hosting panel (CWP, Plesk, or WHM), create a new empty database, a database user, and a secure password. Record these details.


Step 4: Import the Database (Destination Server)

Now, import the .sql file you transferred into your new empty database:

mysql -u NEW_DB_USER -p NEW_DB_NAME < database_backup.sql

  •  
 

Migrating a WordPress site via SSH is much faster and safer than using plugins because it handles large databases and thousands of images without timing out.

Here is a Knowledge Base guide designed for your WHMCS setup.


Article Title: Advanced WordPress Migration via SSH (Server-to-Server)

Category: Hosting / WordPress

Overview

Moving a WordPress site manually via SSH is the most efficient method for large websites. This process involves two main parts: moving the Files and moving the Database.

+1

Step 1: Export the Database (Source Server)

Log into your Old Server via SSH. Navigate to your website root (usually public_html) and export the database.

 
Bash
 
# Export the database to a file
# Tip: Check your wp-config.php for these credentials
mysqldump -u DB_USER -p DB_NAME > database_backup.sql

Step 2: Transfer Files and Database (Destination Server)

Log into your New Server via SSH. We will use rsync to "pull" everything directly from the old server to the new one.

 
Bash
 
# Navigate to your new website directory
cd /var/www/vhosts/domain.com/public_html

# Pull all files from the old server
rsync -avzP root@OLD_SERVER_IP:/home/username/public_html/ .

Note: The . at the end means "copy into the current folder."


Step 3: Create a New Database (Destination Server)

On your new hosting panel (CWP, Plesk, or WHM), create a new empty database, a database user, and a secure password. Record these details.


Step 4: Import the Database (Destination Server)

Now, import the .sql file you transferred into your new empty database:

Bash
 
mysql -u NEW_DB_USER -p NEW_DB_NAME < database_backup.sql

Step 5: Update wp-config.php

Your site is now on the new server, but it is still trying to talk to the old database. You must update your configuration file.

 
  1. Open the file: nano wp-config.php

  2. Update these lines with your new credentials:

  • DB_NAME
  • DB_USER
  • DB_PASSWORD
  • DB_HOST (usually localhost)

Step 6: Handle URL Changes (Optional)

If you are also changing the domain name (e.g., old-site.com to new-site.com), you should use WP-CLI to update all links in the database instantly:

# Install WP-CLI if not present, then run:
wp search-replace 'https://old-site.com' 'https://new-site.com' --all-tables

Step 7: Final Cleanup

For security, delete the database backup file so it isn't accessible via the web:

rm database_backup.sql



All In one Script

#!/bin/bash

# --- CONFIGURATION (Edit these) ---
DOMAIN="yourclientdomain.com"
OLD_SERVER_IP="203.88.144.75"
NEW_SERVER_IP="203.88.144.78"

# SSH Details (Ensure you have SSH keys set up or be ready to type password)
REMOTE_SSH_USER="root"
REMOTE_SITE_PATH="/home/username/public_html"
LOCAL_SITE_PATH="/var/www/vhosts/$DOMAIN/public_html"

# Database Details (Found in old wp-config.php)
DB_NAME="old_db_name"
DB_USER="old_db_user"
NEW_DB_NAME="new_db_name"
NEW_DB_USER="new_db_user"

# Email Details
EMAIL_USER="info@$DOMAIN"
EMAIL_PASS_OLD="Honest@2020KR"
EMAIL_PASS_NEW="Honest@2026KR"

echo "------------------------------------------"
echo "???? Starting Full Migration for $DOMAIN"
echo "------------------------------------------"

# 1. DATABASE MIGRATION
echo "???? Step 1: Exporting Remote Database..."
ssh $REMOTE_SSH_USER@$OLD_SERVER_IP "mysqldump $DB_NAME" > remote_db.sql
echo "???? Step 2: Importing into New Database..."
mysql $NEW_DB_NAME < remote_db.sql

# 2. FILE MIGRATION
echo "???? Step 3: Transferring WordPress Files..."
rsync -avzP --exclude 'wp-config.php' $REMOTE_SSH_USER@$OLD_SERVER_IP:$REMOTE_SITE_PATH/ $LOCAL_SITE_PATH/

# 3. EMAIL MIGRATION
echo "???? Step 4: Syncing Email via IMAP..."
imapsync --host1 $OLD_SERVER_IP --user1 $EMAIL_USER --pass1 "$EMAIL_PASS_OLD" --ssl1 \
--host2 $NEW_SERVER_IP --user2 $EMAIL_USER --pass2 "$EMAIL_PASS_NEW" --ssl2 \
--automap --addheader --syncinternaldates --quiet

echo "------------------------------------------"
echo "✅ Migration Complete for $DOMAIN!"
echo "------------------------------------------"

How to use this script:

  1. Create the file: nano migrate_all.sh
  2. Paste the code and update the variables at the top.
  3. Make it executable: chmod +x migrate_all.sh
  4. Run it: ./migrate_all.sh

A Quick Warning:

For the WordPress Files section to work perfectly, you need to ensure the Ownership is correct after the transfer. If you are using CWP (CentOS Web Panel), add this line to the very end of your script:

Bash
 
chown -R vmail:vmail $LOCAL_SITE_PATH

Was this answer helpful?

« Back