DesertFlood

Bring life to a barren, technological wasteland

Migrating Wordpress Multisite

Using my new PHP setup method, I migrated a bunch of PHP applications over to my Linode. But I saved the hardest challenge for last: migrating my Wordpress multisite install. There are 5 active sites inside of that install and about 3 inactive sites, as well as a decent amount of uploaded media. I wanted to figure out all of the other wrinkles first, before I tackled the most important PHP application. As if all of that wasn’t enough, I decided that I wanted to move the Wordpress installation from its previous domain (desertflood.com) to its current domain (wordflood.net).

After reading through multiple sites about Wordpress migrations, I decided to take the migration in two steps.

  1. Move the site using the existing domain and using my /etc/hosts file to access the existing domain via the new IP address.
  2. Change the domain on the new Wordpress install.

Moving to the New Server

After all of the worry, the actual move turned out to be fairly straightforward. I was already using automysqlbackup to create nightly backups of my MySQL databases and rsync to create offsite backups of my files. Thanks to that, and shell access on both servers, it was fairly trivial to copy both the Wordpress files and database to the new server.

I had already created a home directory and user account for the new Wordpress install, using my setup script. After transferring my files from the old server to the new server and copying the database backup from the old server to the new server, I was able to load the backup into my new database, using the mysql command line tool.

rsync -rav jmartin@litho.joyent.us:domains/desertflood.com/web/public/ /srv/www/wordpress/public_html
scp jmartin@litho.joyent.us:/users/home/jmartin/backups/db/latest/jmartin_mjm_wp3_week.34.2012-08-25_01h03m.sql.bz2 /home/wordpress
bzip2 -d /home/wordpress/jmartin_mjm_wp3_week.34.2012-08-25_01h03m.sql.bz2
cat /home/wordpress/jmartin_mjm_wp3_week.34.2012-08-25_01h03m.sql | mysql -u wordpress -p wordpress

I was already using nginx on my Joyent shared account. That being the nginx setup easy as well. I copied the nginx configuration file from the old server, to merge it into the configuration file for the new server.

scp jmartin@litho.joyent.us:etc/nginx/sites/desertflood.conf .
ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled

Then, on my laptop, I pointed my domains to the new server, using /etc/hosts.

66.175.215.121 desertflood.com www.desertflood.com thosemartins.desertflood.com thosemartins.us minorthoughts.desertflood.com minorthoughts.com www.minorthoughts.com www.thosemartins.us

After I edited my wp-config.php file to point to the new database, I was able to access Wordpress on the new server.

Moving to the New Domain

I was worried about this too but it turned out to be almost as easy as moving the actual Wordpress installation. There were just three steps.

  1. Edit the wp-config.php file to change the DOMAIN_CURRENT_SITE parameter to the new domain.

  2. Update the MySQL database. The MySQL database had references to the old domain scattered all throughout it. My natural inclination would be to just do a global search and replace on the database backup, before loading it into MySQL. However, Wordpress has a lot of serialized data in the database. You can’t just change values there, without breaking those columns.

    Fortunately, the internet has already solved that problem for me. Interconnect IT mentions it in their guide to migrating a Wordpress/WPMU/BuddyPress website. They developed a tool for safely searching and replacing in the database, using PHP. I temporarily installed the “Safe Search and Replace” script and used it to change all instances of desertflood.com to wordflood.net in the database.

  3. Finally, in the ‘Domain Mapping’ section of Wordpress’s Network Admin, I changed the Server IP Address to the IP of the new server.

And, just like that, Wordpress was live on the new domain.

WP Super Cache / MultiSite / nginx

One final note. On Monday, I decided to activate the WP Super Cache plugin, to add that extra bit of oomph to the site’s loading speed. I’ve used it before but it’s been a while. When I turned it on, I ran into a nasty bug that shows up when using WPSC 1.1 with nginx. The plugin assumes that the environment variable SERVER_NAME is configured, but nginx doesn’t set that environment variable.

The end result is that Wordpress caches whichever site the administrator last visited. Then nginx serves out the content for that site to visitors for every other Wordpress site. In effect, the administrator’s last visited site gets cloned across all of the Wordpress sites.

Fortuantely, donncha posted a development version of WPSC that fixes the SERVER_NAME problem. Once I installed it, my caching ills went away.