Articles on: Guides

Manual Migration via SSH

If our Automated Migration Tool is slow or not working or you have a large website with lot of files and large database, your best bet is to transfer the website using SSH method.


Pre-requisites:


  1. Make sure you have SSH login details of both source and destination websites.
  2. This guide also assumes that you have a blank WordPress site at the destination website.


At The Source


We need following commands to be working at the source website's server:


  • wp (WP-CLI client)
  • scp (to transfer files)
  • tar and zip commands (for compression)
  • mysqldump (used by WP CLI to dump database)


All of the above are standard linux utilities.


Login via SSH to the source website:


ssh user@source.com

Lets backup the entire WordPress folder, excluding the wp-config.php file. This has been done to avoid any wp-config.php related issues in the destination website.


Note: This command assumes that you are in the WordPress folder.


# Change to the root of your WordPress folder
cd public_html
tar --exclude='wp-config.php' -czf wordpress_files.tar.gz -C "$(pwd)" .


Then export the database and zip (or tar) the files.


# Export DB
wp db export wordpress_db_backup.sql
# Tar (zip) the db .sql file
zip wordpress_db_backup.zip wordpress_db_backup.sql
rm wordpress_db_backup.sql


It is time to transfer these files & db backup to the destination website's server.


Replace the <dest_ssh_user> (including the angle brackets) with the destination's SSH username and <dest_ssh_host> with destination's SSH host (IP or Hostname).


If you have a SSH key based authentication, it will simply work, but you may have to generate a key pair and copy them in the source serverOR, if you have SSH password baed authentication, just enter the password.


scp wordpress_db_backup.zip wordpress_files.tar.gz <dest_user>@<dest_ssh_host>:/tmp/


Cleanup


rm wordpress_db_backup.zip wordpress_files.tar.gz


At The Destination


Login to the SSH via terminal and verify that the files are indeed arrived in /tmp folder


ssh user@dest.com
cd public_html
ls /tmp


Extract the files and db files.


tar -xzf /tmp/wordpress_files.tar.gz -C "$(pwd)"
unzip -o /tmp/wordpress_db_backup.zip -d /tmp/


Import database


wp db import /tmp/wordpress_db_backup.sql


Verify the files were extracted successfully


wp core verify-checksums 
wp cli cache clear


If you are changing domain during migration, say from source.com to dest.com, then run the following command, otherwise it is not required:


Replace OLD_DOMAIN and NEW_DOMAIN properly in these commands.


wp search-replace "OLD_DOMAIN" "NEW_DOMAIN" --all-tables
wp option update home "https://NEW_DOMAIN"
wp option update siteurl "https://NEW_DOMAIN"


Flush caches


wp cache flush
wp rewrite flush


Cleanup


rm /tmp/wordpress_db_backup.zip /tmp/wordpress_db_backup.sql /tmp/wordpress_files.tar.gz


Updated on: 24/12/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!