How to Move a Wordpress site Manually from one Location to another

Sun, Mar 13, 2011

I've been doing some Wordpress development for the last year or so. A few client projects, some personal etc.

A common chore that I find myself doing is developing the sites on one server and then moving them to the next. Very often I'll be developing on a virtual machine instance on my local machine and then placing the files online later. I also get asked about this by various people a lot - and even though there are a lot of results in Google, I still get asked.

Just copying the files and exporting and importing the database will not do, so there are a few extra steps you need to take to do this successfully.

Wordpress has a built in feature to import data from another Wordpress site, even including users etc. I've used it in the past, but I would say that it does not work as well. Not only do you have to do the whole install procedure first before you import, but you can only pull data in from a machine accessible to the one that's doing the importing.

I saw somebody ask this question on Stack Overflow, so I wrote an answer that is basically the same as the solution I'm providing here. The asker accepted my answer and I thought it was valuable to others.

So the best way to move Wordpress sites between two locations is to do it like this:

  1. You move the files via ftp or scp etc..
  2. Move the database, using export/import in phpMyAdmin or mysql dump
  3. Edit your configuration (in /wp-config.php ) to reflect the new DB settings.
  4. Execute the following statements in phpMyAdmin's import or from the mysql command prompt (copy paste the following code):
[gist id="866373" file="move-site-wordpress-mysql-settings.sql"]

Of course if you're using some unorthodox plugin that stores it's own version of your site's location or domain, you might run into additional problems. I can't help you there. But I've used a lot of plugins and I haven't seen any plugin that breaks this method. So it's highly unlikely.

Note. You cannot do a simple find/replace on the values in the wp_options table, because some of the values there are stored as serialized strings and serialized strings are fragile, so you can't replace values so easily within them.

A Stack Overflow user called @Yarin pointed out that there is a much easier way to update the site urls: Just harcode the url settings into /wp-config.php. That way you don't have to do the database update on your wp_options table. Valid point. Here's how you'd do that:

[gist id="866373" file="wp_options.php"]

That's a nice way to do it if you want to keep it in the config file, but you will still have to update your posts manually.

But how do the ninjas do it?

Ok, so now you know how to move a Wordpress site between two locations. But doing things like this manually can be a bit error prone so you've got to ask yourself: "Do the ninjas really do it this way?"

In short: No

Ninjas, move Wordpress sites using scripts using a command line shell.

** I was going to write a short script that exports/imports for you using either bash or PHP, but I soon realized how much variation can be in people's setup - as in some have access to console, some don't - some have access to mysqldump and some don't etc... **

If you post in the comments what kind of method would be the most useful, I'll be happy to update this post and add that to this blog post. Eg. PHP only, ssh access on both sites, etc...