Migration Method 2: SSH & WP-CLI

In order to move your site with the WordPress command line tool(WP-CLI), you will need a SSH connection on both computers as well as a working WP-CLI tool on the servers. Migration via the command line is the most certain migration method as you can control everything that is happening.

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<br>WP-CLI 2.2.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 export file has table definitions (for example ENGINE=MylSAM), they must be removed.

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

In addition, if you would like the table prefix to be something other than wp_, it has to 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/old-prefix_/wp_/g' ~/wordpress-database.sql

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

wp-user@123.123.123:~$ exit<br>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<br>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-content folder. In case 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 answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us