Skip to main content

Migration Method 2: SSH & WP-CLI

If you're used to working with SSH, it is the most reliable way to migrate your site.

Updated today

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)

Host: example.fi-c.seravo.com
SSH-port: 10350
user: example
WordPress installation directory: /data/wordpress/htdocs

1. Start by logging in to the old server

2. Check that WP-CLI is installed (WP-CLI tool installation guide)

wp --version 

3. Create an export file of the WordPress database

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

wp db export --path=/var/www/htdocs/ ~/wordpress-database.sql

If the export file has table definitions (for example ENGINE=InnoDB or ENGINE=MylSAM), they must be removed.

sed -i 's/ENGINE=InnoDB//g' ~/wordpress-tietokanta.sql
sed -i 's/ENGINE=MyISAM//g' ~/wordpress-database.sql

In addition, if your table prefix is 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).

sed -i 's/old-prefix_/wp_/g' ~/wordpress-database.sql

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

ssh [email protected] -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.

rsync -avz --stats [email protected]:~/wordpress-database.sql /data/db
rsync -avz --stats [email protected]:/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.

6. Import the database with the WP-CLI tool

First you need to reset the current (usually empty) database. Remember to take a backup if you are importing the database to an existing site.

wp db reset --yes

After the reset, you can import the database.

wp db import /data/db/wordpress-database.sql

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

wp search-replace "/var/www/htdocs/wp-content" "/data/wordpress/htdocs/wp-content"

If you need to test the site before publishing, change our development address to the database.

wp search-replace "//example.com" "//example.fi-c.seravo.com" --all-tables
Did this answer your question?