Migrating a hosted WordPress site to your local PC

October 12th, 2008

This has wasted me hours and hours of time and effort, but I eventually got there. I want to move my WordPress site up from version 2.2.3 to the latest version 2.6.2.

I don't like to put myself through the pain of upgrading every time there's a new WordPress version, but I'm quite far behind now and there's a particular plugin I want to use which won't work under 2.2.

So, before upgrading live, I thought I'd migrate everything onto my laptop, do an upgrade there and see how I get on. If it just doesn't work, or breaks PodPress, for example, then I won't bother trying it on my live site.

Theorectically, migrating should just be a case of:

  • Download all the files using FTP.
  • Export the data from MySQL.
  • Put Apache and MySQL on my laptop using XAMPP.
  • Put all the downloaded files into the web directory hierarchy.
  • Create a new database on the laptop with the same name and user as on my web host.
  • Import the data into this new database.

That's basically what you do but, as ever with this kind of thing, it's the fiddly little extra things you have to do to make it work that always trip you up and take forever to figure out.

The best directions (though neither of them complete) for doing this task were:

http://mark-kirby.co.uk/2008/how-to-create-a-local-copy-of-a-wordpress-site/

and

http://www.aniquito.com/2008/08/12/how-to-move-wordpress-from-hosting-site-to-local-computer-or-to-a-new-domain/

The latter is good because it has some search/replace commands that you can run in phpMyAdmin to replace full URLs with relative paths.

There's also:

http://weblogtoolscollection.com/archives/2008/01/03/install-wordpress-locally-part-2-of-2/

Which doesn't add much, but contains some information about large SQL files and phpMyAdmin.

I mainly used the first of those pages. However, additional points to note before following these instructions:

  1. Disable all plugins before exporting the data and downloading the files (you can turn them back on later, once everything else is working).
  2. Make sure you've change the siteurl and home options in phpMyAdmin. After changing them search again and make sure they really have got the localhost value in them now.
  3. Comment out the WP_CACHE line in the wp-config.php file:

    <?php
    // ** MySQL settings ** //
    //define('WP_CACHE', true); //Added by WP-Cache Manager
    define('DB_NAME', 'mydb');    // The name of the database
    define('DB_USER', 'mydbuser');     // Your MySQL username
    define('DB_PASSWORD', 'fiendishlycomplicatedpassword'); // ...and password
    define('DB_HOST', 'localhost');    // 99% chance you won't need to change this value
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', '');

    For a long, long while, when I browsed to the local site I got redirected to the Web site home page. I puzzled with this for hours and eventually after trying lots of different things, it went away. I'm not quite sure how I solved it. I think it was something to do with caching, so make sure you comment out the line above if you use the wp-cache plugin.
  4. Make sure the DB_HOST in this file is localhost. It should be anyway, but mine wasn't.
  5. If you want to use permalinks, you will need to make a change inside Apache's httpd.conf file.

    In my case this is located within this directory:
    D:\programs\xampp\apache\conf

    Open that in a text editor. Use the search facility in the editor to find "rewrite". The line you need looks like this:

    #LoadModule rewrite_module modules/mod_rewrite.so

    You need to take away the hash sign so it looks like this:

    LoadModule rewrite_module modules/mod_rewrite.so

    Save the file.
  6. Make sure the .htaccess file in the root of your wordpress directory (in my case this directory is called itauthor) contains the following:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /itauthor/index.php [L]
    </IfModule>

    Note the name of the wordpress directory in the RewriteRule. You may need to change:

    RewriteRule . /index.php [L]

    to:

    RewriteRule . /yourwordpressdirectory/index.php [L]

    If the WordPress files aren't in the root of your web server.
  7. Now restart the apache2 service in the Windows services dialog box.
  8. Live Writer likes to use URLs, so if you use it to post to your blog you'll probably have to spend a while carefully searching/replacing URLs to relative paths. For me, I wasn't too bothered as I'm just going to use this as a sandbox for checking the effects of running through the upgrade process.

Leave a comment