Migration Method 2: SSH & WP-CLI

In order to move your site with the WordPress command line tool, you will need a SSH connection on both computers and WP-CLI must be installed on both computers. Migration via the command line is the most certain migration method.

Information of old server (example)

IP-address: 123.123.123.123
SSH-port: 22
user: wp-user
WordPress installation directory: /var/www/htdocs

Seravo.com information (example)

address: esimerkki.wp-palvelu.fi
SSH-port: 10350
user: esimerkki
WordPress installation directory: /data/wordpress/htdocs

1. Start by logging in to the old server

my-computer:~$ ssh wp-user@123.123.123.123

2. Check that WP-CLI is installed

WP-CLI tool installation guide

wp-user@123.123.123:~$ wp --version
WP-CLI 0.17.0

3. Create an export file of the WordPress database

NOTE! Remember to set WordPress’s installation directory with the –path parameters.

wp-user@123.123.123:~$ wp db export --path=/var/www/htdocs/ ~/wordpress-database.sql

If the message file has table definitions (for example ENGINE=MylSAM), they must be removed. In addition, if you would like the table prefix to be something other than wp_, it should be changed in both table names and e.g. in the field names of the wp_options table (e.g. wp_user_roles).

wp-user@123.123.123:~$ sed -i 's/ENGINE=MyISAM//g' ~/wordpress-database.sql

4. Log in to Seravo.com with the SSH login details

wp-user@123.123.123:~$ exit
my-computer:~$ ssh example@example.seravo.com -p 10350

5. Copy WordPress’s wp-content directory from the old server
The migration may take tens of minutes depending on the size and quantity of the exported files.

example@example-wordpress:~$ rsync -avz --stats wp-user@123.123.123:~/wordpress-database.sql /data/db
example@example-wordpress:~$ rsync -avz --stats wp-user@123.123.123:/var/www/htdocs/wp-content /data/wordpress/htdocs

NOTE! The command above assumes that the only things that needs to be moved are the contents of the wp-contentsfolder. Incase the old site uses Bedrock or some other custom directory layout you might need to add symbolic links to the site for it to work correctly.

More information about directory layouts can be found here: https://seravo.com/docs.

6. Import the database with the WP-CLI tool

example@example-wordpress:~$ wp db import /data/db/wordpress-database.sql

7. Ready! Finally, make any necessary search-replace database changes

example@example-wordpress:~$ wp search-replace "/var/www/htdocs/wp-content" "/data/wordpress/htdocs/wp-content"

Did this solve your problem?