Technical notes on WordPress when switching hosts or URLs

Generalized, here’s the process I used to move Waffle from my old host to my new host:

  1. ‘Dump’ the database - saving everything into the SQL queries needed to re-construct the database. This is available from the excellent online database manager PHPMyAdmin or the bundled command line tool mysqldump.
  2. Download all the files from the old server (fairly naturally). (It’s important to do the database dump the very first thing you do before this step; if it takes a long time and your old host close on you, there’s a fair chance there’ll be database data you won’t have, but there’s a good chance you already have your files on your hard drive.)
  3. At this stage it might be tempting to upgrade to a newer version of WordPress immediately. However, I recommend getting your current version up and running first, if for no other reason than to see that everything basic still works. So, instead of upgrading right now, edit wp-config.php to point to your new database (create this new database using your host’s admin tool if you haven’t already).
  4. Upload the old files to the new server.
  5. Restore the database. Possible tools include:

    • The aforementioned PHPMyAdmin
    • The mysql command line tool on the new server (via ssh or telnet)
    • In combination with the uploaded dump called “tempfile”, a simple PHP script along the lines of

      < ?php mysql_connect(host, name, password); mysql_select_db(database); mysql_query(implode('',file("tempfile"))); ?>

      (For many reasons such as security and not running it again after two months having it duplicate everything, remember to delete the script and the uploaded dump (”tempfile”) immediately after it’s been run.)

If you’re changing the URL of your set up, remember to take these steps:

  1. In the options table, change the row with the option_name “siteurl” to have the option_value of your new URL. (If a row exists with the option_name “home”, change that one too.)
  2. If you can have an .htaccess file (if you’re on Apache) and you use the Permalink Structure feature to make nicer URLs, make sure that file gets rewritten by re-saving it. (Remember to set the correct permissions of the .htaccess file, since normal permissions will not normally allow WordPress to rewrite the file.)
  3. If you have mod_redirect, use this .htaccess file in your old URL root to redirect any request to that URL to the new URL:

    RewriteEngine On
    RewriteRule ^/(.*)$ http://your.old.url$1

    If your new path is not at the root of a domain, insert RewriteBase /path/to/new/path in between. (Be sure to leave off the trailing slash.)

No comments yet.

Leave a comment

Your e-mail address is never shown. If you type a line break in the comment, it will show up as a line break (naturally). The following HTML is allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)


Please note: Your comment will not show up at once. Unless you're spamming or being abusive, you have nothing to worry about. (Read the full policy.)