Moving A WordPress Blog To A New Host

I facilitate several WordPress blogs, several of which I installed on DiscountASP.NET.  I wrote a blog about the process, and then as now it felt like I had to shoehorn WordPress onto their system.  I, as well as others, began to have problems administrating our blogs (notably, difficulties adding plugins or upgrading versions).

I’ve also hosted a number of domains with Applied Innovations, and I knew they added some new capabilities and a crazy new plan for Webmatrix hosting, especially ensuring the right capabilities for WordPress and other WAMP stack applications (such as Joomla, Drupal, and so on).  Better pricing and the right features-it was time to migrate.

I migrated two blogs today using the steps below, and I’m going to migrate a couple others as their current hosting nears expiration.  Moving a WordPress blog involves moving both files and a database; each has its own method.

There are a number of ways to backup and restore a WordPress blog.  The official documentation is http://codex.wordpress.org/WordPress_Backups and http://codex.wordpress.org/Restoring_Your_Database_From_Backup.  There are several plugins you can install which will backup your blog on a schedule—it’s not a bad idea to use these.  I think the method below is pretty easy and effective for a migration, but isn’t necessarily a process you want to repeat every week as part of a regular backup (unless you script it, which is possible).

Step 0: Get The Tools

I used two tools to migrate my blogs—FileZilla, to transfer the files, and MySQL Workbench to migrate the databases.  Both are free and widely available.

Step 1: Prepare Your New Host

Before you do anything, make sure your new hosting is set up, that you can log into your control panel, and you have both a new website and database set up.  On some hosts (such as AppliedI), the FTP login is the root folder, but the WWW service points to s subfoler—make sure you know where to put the files.  Keep track of your passwords!

Step 2: Clean Up Any Messes

Migration will involve exporting data from your current blog’s database, then importing all of it again into your new blog’s database.  This process, on both ends, can take some time, so obviously the less data you try and move the easier it will become.  This is the time to log in to your control panel, empty all the spammy and trashed comments, clear out posts which haven’t been published if you don’t plan on finishing them, etc.  Also, if you have any custom DNS entries made on your current host’s nameservers, such as redirecting email to GMail or Hotmail, copy those settings.

Step 3: Download The Blog Files

Log in to your current blog, and download all the files.  You’ll need everything in your blog root, as well as the three subfolders (wp-admin, wp-content and wp-includes).  Download these to your local machine, because you’ll need to edit one of them.  Don’t delete anything from your current site, just in case you need something again.

Step 4: Export Your Blog’s Data

This step requires the most explanation.  It’s not difficult, there are just a number of small things which need to be done.

Start up MySQL Workbench; the Workspace area is divided into three columns, the far right of which is Server Administration.  Below this listbox, click New Server Instance.

image

Choose the Remote Host option, and enter the name of your current blog’s MySQL Server, then click Next.

image

Give this connection a better name in the Connection Name box; this will populate a connection in the SQL Development column.  Change the Username if necessary (it probably is).  If you want/can store the password in MySQL Workbench, click the Store in Vault button next to Password, and enter the password in the dialog.  If you don’t store the password, you’ll be prompted when you try to connect.  If you need to, adjust other settings, but you probably won’t need to.  Click Next.

image

The database connection settings will be tested.  If Workbench cannot connect, you’ll need to fix whatever is wrong before you can continue.  Click Next once everything is OK.

image

Remote management takes some additional configuration, and it’s not something we’re going to do here.  If you want to use MqSQL Workbench to manage your database, you can set this up, but it’s not necessary to export/import data.

image

A bunch of intermediate steps will be skipped, and we then assign a useful name to the new Instance.  Clicking Finish here will close the wizard and create the connection and the instance.

image

Select the new instance with a single click, then choose to Manage Import/Export.

image

You may be prompted to choose the connection.

image

This is the most important set of our export.  Select your database with a single click, then choose which items correspond to your blog.  In a WordPress database, there are only tables, and by default they are prefaced with “wp_”.  The image below shows a default install, for reference.  To make the import easier, choose to Export to a Self-Contained file.  For most blogs, this will be OK, but for very large blogs, you can choose to export individual tables into separate files.

image

The export will take a few minutes—watch the progress indicator.  When complete, you can close the Import/Export window.  We need to make a couple small edits to the export file before we can use it.  If you exported to multiple files, you’ll need to make this change to all of them.

About 22 lines down is the command to create a database if it doesn’t exist.  Since our user probably doesn’t have the correct permissions to do this, we need to commend this out by adding two dashes and a space at the beginning of the line (the space is necessary).  A couple lines further down is the USE directive.  This needs to be changed to the name of our new blog database.

image

image

Step 5: Import Your Blog’s Data

If you haven’t done so already, make sure your new blog database is set up, and has a login user ID created.

Back in MySQL Workbench, under the SQL Development column, click the New Connection link.

image

Just as before, give this connection a useful name, then update the Hostname and Username (if necessary).  Again, if you want/can store your password in the vault, do so.  Once everything is correct, click OK.

image

When all is well, we’ll have a new entry in the Connections listbox.  Double-click the new blog entry to open the SQL Editor.

image

In the SQL Editor, open the dump file you created above, double-check you made the minor (but important) edit above, and run the script.  The tables should be created and populated.  If you dumped to multiple files, you’ll need to repeat this process for every file.  When all the scripts have been run, you can expand Schemas >> [your database] >> Tables and see the WordPress tables.  If you’re familiar with SQL, you can query some data at this point, too.

image

Step 6: Upload Blog Files (edit the config first!)

Before we do anything, we need to modify the database connections in our downloaded wp-config.php to point to our new host’s database and server.  These are the first four settings in the file.

image

Save this file, and upload all the files to the new host.  Make sure you’re in the right folder, whether it’s the root or a subfolder.  Once this is complete, you should be able to view your blog through a temporary URL, or your actual URL, depending on how your site is configured at this time.

Step 7: Update Nameservers

Since you’ve moved to a new host, it’s now time to update the nameservers for your domain.  This is now a good time to download any email you want to keep from your host’s email system.  You’ll probably need to update your email clients, too.

Congrats!  You should soon have your blog completely set up on your new hosting service.  Remember to cancel your old service!