Moving a WordPress Site

February 4, 2011

Moving a WordPress site can be a real pain. Links break, images become MIA, the list goes on and on. It’s common to develop a site in another folder on the production server or in a testing environment on another domain altogether. The issue is that migrating the files and database, while not complex, can be a nerve racking experience, especially when you have an excited client constantly pressing the refresh button on their browser. We’ve come to follow a step by step procedure that helps make the transition a much smoother exercise. During this entire process, we ask any users of the development and future users of the production to refrain from accessing either domain.

  1. Download all the files on the development server to your local drive. You’ll probably be okay if you just grab everything in ‘wp-content’, but we just grab it all as a matter of habit. This ensures that you have any files others may have modified, namely uploaded images.
  2. Next you’ll need to export your development database. phpMyAdmin, which is standard in most web control panels, makes this really simple. Just hit the ‘Export’ tab at the top. The default settings should kick out a .sql file which you will be able to import in the next step. Be sure to check the ‘Save as File’ option at the bottom of the screen.
  3. Now login to phpMyAdmin in the production environment. Click the ‘Import’ tab at the top, browse for the .sql file from the previous step and hit ‘GO’.
  4. Since the site is changing URL’s, we need to update portions of the production database. We’re going to basically do a find and replace using sql commands in 3 main areas of the productiondatabase.
    1. First we’ll tackle a couple fields in the wp_options table by using the ‘SQL’ tab in phpMyAdmin. Copy and paste the following SQL statement, replacing ‘http://www.development.com’ with your development domain path (subfolders as well if that is the case), and ‘http://www.production.com’ with your new production domain path.
      UPDATE wp_options SET option_value = replace(option_value, 'http://www.development.com', 'http://www.production.com') WHERE option_name = 'home' OR option_name = 'siteurl';
    2. Second, we’ll address the guid field in the wp_posts table. Again, modifying the URL’s to your specific paths.
      UPDATE wp_posts SET guid = replace(guid, 'http://www.development.com','http://www.production.com');
    3. We’ll modify the post_content field in the wp_posts table.
      UPDATE wp_posts SET post_content = replace(post_content, 'http://www.development.com', 'http://www.production.com');
    4. Optionally, we may need to update the wp_postmeta table as well depending on plugin usage.
      UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.development.com', 'http://www.production.com');
  5. On your local set of files, which we downloaded in Step 1, we’ll need to modify wp-config.php. For the most part, you’ll need to modify DB_NAME, DB_USER and DB_PASSWORD, but this information is all specific to the settings on your production server.
  6. Upload the local files to the production environment. Be sure to upload to the you specified in Step 4. Again, this all depends on how you’ve set things up.
  7. Once the upload has completed, you should be ready to view your site. If you experience broken links on the site, you may have to login to the administration side of the production site and access ‘Settings > Permalinks’, click save to rewrite your .htaccess file.

While this process is not 100% fool-proof, it’s a great way to alleviate some of the panic that ensues when a client is ready to move to production.

2 Responses to “Moving a WordPress Site”

  1. Anamaria says:

    Thank you so much for these clear instructions. Really helpful!

Leave a Reply