I’m going to run through how to migrate a WordPress website with WP-CLI and rsync. When it comes to migrating a WordPress website efficiently, the combination of WP-CLI and tools like rsync reigns supreme.

This method works wonders, especially for large websites where traditional plugins might struggle due to limited disk space for backups.

This migration technique, conducted via the command line, is much simpler than it appears.

In this article, we’ll walk through migrating a website to Pressillion using WP-CLI and rsync.

Similar steps can be applied to almost any host if you have SSH access and make necessary adjustments accordingly.

Throughout this guide, we’ll work with the system user for our websites, not the root user.

Part 1. Backup Your Origin Website Database with WP-CLI

To initiate the process, establish an SSH connection to your current website’s server to export the backup. Navigate to your WordPress installation’s directory—on Pressillion, for instance, it’s typically:

/var/www/site.url/htdocs

Depending on your setup, common paths might include:

/sites/site.url/htdocs

/home/systemusername/public_html/

/home/systemusername/www

Once connected, confirm the correct path.

Export Your Database

Ensure you’re operating as your website’s system user with:

sudo -u systemusername

Then, export your database using WP-CLI with the following command:

wp db export database.sql –all-tablespaces –add-drop-table

It’ll notify you once the operation completes, which might take some time for larger databases.

Part 2. Create and Prepare Your Destination Website

Before starting the migration, there are some quick preparatory steps:

Step 1. Create Your Destination Site

In your account’s Sites page, craft your website. If your origin site has an SSL, consider adding one here too.

Keep caching and security features turned off for now. Enable them once the site has been successfully imported. For guidance on creating new websites, refer to this knowledge base article: New WordPress Website

Once created, you’ll have everything in place to import your origin files, including a newly created WordPress database and a properly configured wp-config.php file.

Step 2. Connect to Your Pressillion Server

If it’s your maiden voyage connecting to a Pressillion server, follow these guides to get started:

Step 3. Navigate to Your Sites Directory

Once connected, head to your website’s directory using the command (replacing site.url with your URL):

cd /var/www/site.url/

Step 4. Remove Your Existing WordPress Files

Prepare to pull over the entire WordPress installation by removing the existing one:

rm -R htdocs

Now, recreate your htdocs directory:

mkdir htdocs

As Pressillion stores the wp-config.php one level up outside of the /htdocs directory, there’s no need to make a copy or relocate it beforehand.

Part 3. Copy Your Website Files from Your Origin Server to Your Pressillion Server with rsync

Rsync allows the movement of files between servers. Here, we’re pulling files from the origin server to your Pressillion server. Run these commands directly from inside your destination (Pressillion) server.

Option 1. Pull your files with rsync: System User + Password

This command will fetch your files from the origin server to your destination. Here’s the basic syntax:

rsync -avz -e ssh systemuser@199.199.199.19:/path/to/site.url/htdocs/* /var/www/site.url/htdocs/ --info=progress2

Remember to replace the origin server’s IP address, your system user name, the /path/to/site.url, and site.url with your website’s URL.

You’ll be prompted for your system user’s password before the process begins. If your origin server uses a custom port, specify it with the -p flag.

Option 2. Pull your files with rsync: System User + SSH Key

To use this option, set up your SSH keys so your Pressillion server can access your origin server. First, create a new key pair on your Pressillion server:

ssh-keygen -t rsa

Follow the prompts and list your files with ls -l to view your private and public keys.

Now, display your public key:

cat key.pub

Add this key to your origin server following your host’s documentation.

Then, execute the command to pull your files from the origin server to your Pressillion server:

rsync -avz -e 'ssh -i /path/to/private/key' systemuser@199.199.199.19:/path/to/site.url/htdocs/* /var/www/site.url/htdocs/ --info=progress2

Remember to replace necessary fields like key paths, system user, IP, website path, and site URL.

Verify Your Files

Once rsync completes the transfer, navigate to your site’s /htdocs directory and check if the transfer was successful:

cd /var/www/site.url/htdocs

ls -la

Part 4. Complete Your Migration

Now that the files are copied, proceed to import the database.

Ensure there isn’t a wp-config.php file inside your /htdocs folder before continuing.

Import Your Database

Navigate to your website’s /htdocs directory (if not already there):

cd /var/www/site.url/htdocs

Run the following command to import your database as your system user:

sudo -u systemuser wp db import database.sql

It’ll notify you once the operation completes, which might take some time for larger databases.

Run a Permissions Fix

Ensure your file permissions are correct:

fix perms site.url

Part 5. Migration Checks

Post-migration, do some cleanup to ensure your website runs smoothly:

  • Check Database Table Prefix: Update wp-config.php if necessary.
  • Remove Unnecessary Must-Use Plugins: Disable them by renaming the folder.

Once you’ve confirmed a successful migration, enable caching and security settings as needed.