How To

Migrating A WordPress Site With wp-cli

If scotch is for shippers, clearly margaritas are for migrations!

This is … crazy simple. I wanted to move a site from to (yes, I own that too). While is a Multisite network, is where I put a ton of add-on domains. I was moving a site over and, as it was WordPress, did it in a matter of minutes.

Add the domain to the … domain

Since I don’t care to have multiple hosting accounts, and I’m the only one with SSH/FTP access, it’s safe enough for me to do this. There is a risk when you share multiple domains in one hosting account, that if one gets hacked they’re all vulnerable, but I consider it low in my situation. Every plugin is vetted, every file is checked, and then I went and gave each add-on it’s own FTP account. Neurotic? Thy name is me.

Anyway, I add the new domain to my hosting where I want it.

Create the new DB

I have to make a new database, and generally a new DB user, on the server too.


On existing hosting, I do this:

wp db export

That gives me my SQL file, thanks to WP-CLI. It’ll be named example_com.sql and will sit in my folder with .htaccess and everything else.


I do it via SSH. I go to the new location and run this:

scp -r .

Since I have ssh keys set up, it’s easy. If I don’t, I’ll put in the password, but that’s straightforward.

Edit wp-config.php

Now I have to point to the new DB. Sometimes I name it the same, but usually I don’t, so I’ll edit the DB name, DB user, and password.

Import the old DB


wp db import example_com.sql

Boom. It’s all dumped in! Only two steps left!

Search & Replace

I love this one.

wp search-replace --dry-run

I ALWAYS dryrun test it. This is a serialization safe search, so rarely is it ever going to be an issue to just run, but it lets me make sure I don’t get any wonky results. I never have, so re-run without dry-run.


Delete the SQL file, delete the old files on the old server.


El Chorro Margarita

I moved code. That’s shipping, right? Or is it margaritas are for migrations?

8 replies on “Migrating A WordPress Site With wp-cli”

@Japh: Oh yes, do that if you have a lot of files 😀

It was a fairly small site, but if it’s a big one, I’ll zip it before moving, because watching rsync copy each file over is about as fun as cleaning cat poop at 1am.


WP-CLI is a very powerful tool. Really good demonstration of the same in your post. I wonder how many are still using the ftp download and upload way for website migrations.

I also did a recent post on how to install WP-CLI on your server. Here is a link for the readers.

Deepak Kundu

Do you need to have wp-cli installed on your hosting server to do this? or can wp-cli run locally and ‘point’ at a site on the hosting server?

@Glenn: You’d need to have WP-cli run wherever you have WP. So if you develop locally, it’d be faster to have WP-cli, though in a pinch you could FTP up the files and just run it remotely.

Since I’m using VVV these days, WP-cli is built in, and I always install it in my servers. Makes my life easier.

Comments are closed.

%d bloggers like this: