Script to make WordPress site migrations easier

I’ve cleaned up and release the script that I use to migrate my WordPress sites between my local development server and a live web server. It’s hosted up on GitHub if you care to grab a copy or fork it to make your own improvements.

[box type="note"]

Updates
  • 01/26/2012 – Script now searches thru all custom fields (postmeta table) and replaces any hard-coded URI’s
    [/box]

There have been several attempts by others (many of which are more elegant) in the past to address this problem, but it always seemed like overkill to me. Many of them required a plugin or hacks to the wp-config.php file.

This is my attempt to simplify my own process a bit. If you use the script, I’d love some feedback on how it worked for you.

WordPress Migration

The purpose of this script is to quickly and easily allow the user to update all database references for a WordPress website. Instead of doing a manual, find-and-replace of a MySQL text file, this script connects to your WordPress database and does all of the heavy lifting for you.

WARNING! This script modifies the database as configured in your wp-config.php file. You should make a full backup of your database before using this script.

SECURITY NOTICE – This script should not be left on a live web server as it offers direct access to your database. When you’re done with your migration, delete the script.

Script Installation

  1. Ensure your wp-config.php file has the correct database connection settings.
  2. Upload the wp-migrate.php file into the root directory of your WordPress installation.
  3. Point your web browser to the script (like http://mywebsitedomain.com/wp-migrate.php)
  4. If your wp-config.php file is setup correctly, the script will determine the current “old” website URL.
  5. Set the “New URL” field to the absolute URL you’d like the database updated to.

Additional Notes

  • Depending on the plugins you use, you may get PHP error notices about files not being included. You can generally ignore these.

11 thoughts on “Script to make WordPress site migrations easier

  1. Where exactly is the “migration” part of your script? As I understand, it just replaces the URLs in the WP database – so there is no “migration” going on anywhere, is it?
    I would expect something like rsync or any other mechanism to upload the files to a server – of course integration of git and beeing able to make a ROLLBACK on error are not handled here – there seems to much more to be done to add the term “migration” to this script…

    • Hi @BUGHUNTER,

      You’re correct that this script doesn’t provide a migration in the fullest sense of the word. However that’s the beauty of developing open-source software. I get to choose the name! I’ve hosted the project on GitHub to allow any other programmer to fork the project and make his/her own updates. I’d love to see your take on some of the features you mentioned.

      However, for my needs it does the trick quite nicely!

  2. I just wanted to drop in and say thanks for making this plugin. It worked like a champ for a domain change I just did. It’s definitely easier than doing the search and replace method, and I’m glad to have found it. Thanks!

    • Hi Nick,

      I’m glad that this script could help! I’ve found that it doesn’t work well for serialized values in the database. This primarily affects widgets that may be loaded. As soon as I have a free moment I’ll update the script to handle these items intelligently as well.

  3. This script is awesome, although I froze for a while after running it, because none of my links worked! I had “Not found” error on every post and page :) But saving permalink structure did the trick! Thanks again!

    • Hi Alex,

      I’ve not run into that particular issue before, and can’t think of any particular reason why it would pop up on your site. I’m glad to hear that it worked for you though!

  4. Amazing!

    The migrating business has been such a nightmare for so long. Very grateful for the wonderful job, Philip.

    I wish I understood exactly what your script does, though. Perhaps it’s time for me to properly learn php ;)

    Somewhat related: I found and modified a bash script to automate the set up of a wp local installation (downloading latest version—including favorite plugins—, setting up wp-config, moving directory to htdocs to use with Mamp). Combine with your script, I’ve got both ends of the develpment covered. Sweet!

    • Hi Thomas,

      I’m glad that my script could help you. WordPress represents a great opportunity to learn PHP so I do hope you’ll continue to dive in there. I’d love to see the bash script you’re using and see if it could help my development process to.

      Thanks for visiting and posting!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>