Relocating a WordPress Installation

WordPress is a fine basic website tool, and I’ve used it for a few different odds and ends. One thing it does have that suprises me every time is that it uses a setting for its web address. So as part of the install, it sets this setting and then everything works. Or rather it does, so long as the web address of the application doesn’t change.

Well I’m working on something that I’m developnig locally, checking in to a subversion repository, and then deploying to another server (and other people will be doing the same when they collaborate with me). WordPress isn’t really designed for that, or for the situation where you have a copy of the database, and the code and need to restore it to a different place for any reason. The admin login form is accessible – but then submits to the old location before you can get in to change the settings.

Anyway it turns out to be really straight forward. The URL is in the database and a one-line query mends the problem. I’m putting it here for the next time I need it :)

update wp_options set option_value = '" where option_name = 'siteurl';

I found some complicated instructions for moving a blog too – but this will also work for that scenario. This was wordpress 2.7 (their new and shiny version!), I’m not certain which other versions this would apply to but add a comment if you can expand on this please!

6 thoughts on “Relocating a WordPress Installation

  1. There’s some information on this sort of thing on the WordPress Codex at:

    WordPress is generally very crap about moving a blog from one location to another, whether it be from a development site to a production site or from URL to another. The instruction for moving your site from one hostname to another are unbelievably complicated and come with scary warnings:

    You can also define(‘WP_SITEURL’, ‘http://…’) in wp-config.php to set the site url dynamically. (This also marks it uneditable in the admin interface.

  2. All I can say LornaJane, is that you are *ing brilliant!
    I’ve moved older versions of WordPress, and it is remarkably easy. But I can’t quite remember how I did it. And I didn’t think to post the solution on my blog…

  3. I’m working on a project at the moment with the same problem.

    I think the easiest solution is just to omit the wp_config table when exporting your SQL locally.

    Or just copy the SQL into an update file in your repository. Then you can just run the file and execute the query.

  4. Simon: good tip!

    Michael: Ah, you can set it in the config … that could be a much easier way of doing it, thanks :)

    cereal_girl: I actually use this blog *instead* of a brain, things go here that I know will leak out through my ears and be lost forever if I don’t record them!

    Gavin: The separate SQL could work – although now I know I can put this setting in a config, I might change it to use server-specific config in future. So many possibilities …

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.