Moving a WordPress blog between hosts

This is a tech post, so if that isn’t your thing, feel free to move along!

I’ve been using WordPress for websites and blogs since it’s earliest days, and in earnest since about 2004. In that time I’ve had to move blogs from server to server every so often, as I’ve gone through different hosting companies, our own servers and cloud services. I get asked about it frequently enough that writing a post about how to do it seems sensible!

It is not as technically intimidating as it sounds, assuming you are moving between reasonable hosting providers. The steps are as follows:

  1. Reduce your DNS time outs*
  2. Set up the new server.
  3. Move across the assets (the themes, images and other files).
  4. Export the database.
  5. Import the database.
  6. Check the installation on the new server*
  7. Change your domain name settings.

The * steps are if you need to minimise the down time – they are good, but more technically challenging. You will need to following things to hand:

  1. Account details for your domain name registrar / host.
  2. Login details for the WordPress site (obviously :) )
  3. Login details for your old provider and your new provider.

I know that sounds obvious, but often times people find in surprisingly hard to lay their hands on those things! :)

STEP 0: Before you start, make sure you have a back up of everything! Most providers have some sort of back up/export function. If not, there are WordPress plugins which will do a back up. I generally use step 3 and 4 as my back ups, and don’t remove anything from the old server until the new one is 100% A OK.

Step 1 (optional). If you are comfortable fiddling with DNS settings, then go ahead and drop the TTL (time to live) for your domain. This will enable the switch over to happen more quickly. I usually drop it to 5 minutes, to minimise the chance of comments getting lost on high volume sites. If you have no idea what TTL is, don’t panic, just move on to the next step.

Step 2. Set up the server. Most hosting providers will give you a one-click install for WordPress. If you are prompted for a database user name and password, you can make life a little easier by using the same ones as your existing install (while you are doing step 3, take a peak at the  wp-config.php file to see what they are).

Step 3. Copy the files. You want to copy across the WordPress files, especially the wp-content directory, which will be the largest collection of files, as it contains all the images you have used in your site. FTP is the easiest way to do this, if your providers support it. As a Mac user, CyberDuck is my favourite tool, the FireFTP plugin for Firefox is also good. If the WordPress installation is the only thing on your host, then you can copy across all the files to your new host.

Step 4. Export the database. The database on your old server contains your WordPress settings, blog posts and comments. You’ll want to copy these across! The process for moving this varies from system to system. Most hosting providers will have a control panel with phpMyAdmin. Login and export/download your database, which should give you a .sql file. If you have shell access and are happy with the command line, simply do:

mysqldump --add-drop-table --u DB_USER -p DB_NAME

You'll be prompted for your WordPress database password - the settings for mysqldump [your_database_name] can can be found in the wp-config.php file (they are called DB_USER and DB_NAME).

Step 5. Import the database. Again, using your hosting control panel and phpMyAdmin or equivalent, import your database on to your new server. You may need to create a new database first, if you do, then use the same database name, database user name and database password as your old system (from that wp-config.php file). If you need to do this from the command line, follow these steps:


mysql -u root -p create database wordpress_db
use wordpress_db;
grant all privileges on wordpress.* to 'username'@'localhost' identified by 'password';
exit;
mysql -p -d wordpress < /home/username/wordpress_db.sql

Where “wordpress_db” is the database name DB_NAME  in wp-config.php, and similarly ‘username’ and ‘password’ are copied from DB_USER and DB_PASSWORD in wp-config.php.

Step 6. Check the installation. At this point you’ll want to check that the new server is up and running nicely. However, your domain name (e.g. yoursite.com) will be pointing to the old server. You  can get around this by temporarily editing your hosts file ( ~/hosts on the mac C:\Windows\System32\Drivers\etc\hosts on Windows 7 and Vista). Then going to the site. Again, if you aren’t comfortable editing hosts files, you can skip this step, but you won’t be sure the new server is working for a while longer, and if it isn’t, you will have a bit of down time while you switch back. You’ve probably reached the “phone a friend” stage by that point anyway!

Step 7. Change your domain name DNS settings. to complete the change, you need to make yoursite.com point to your new hosting provider. You’ll need the IP address of your new server (your provider should have supplied this to you). Login to your control panel for your domain (the people you purchased your domain name from – which may be different from your old hosting provider). Update the settings, and wait for the changes to propagate across the Internet. Depending on your settings (see step one) this will take up to 24 hours or so. If you did step 1, this is the moment to put your DNS TTL back to a sensible setting (don’t forget to!).

Enjoy your site running on your new server…

If you have any suggestions or tips, please do leave a comment!

 

Leave a Reply