While there are many reasons to move a WordPress site to a new domain, the one I encounter most is I am developing a site on my own server and need to move the site to the client’s server upon completion. I usually end up performing these types of migrations several times a month and can do it extremely fast and in my sleep with one hand tied behind my back while I hop, skip, and jump rope. That being said, the first time I had to move a WordPress site was not very fun and I had trouble finding a good guide to help me.
Tools you will need to use this guide:
- Web browser
Tools I personally use:
- Dual monitors
Note: I will be writing this guide for moving a site across a cPanel server setup. You can easily apply the knowledge and guides here to nearly any web host or server setup.
The first step is to make sure all WordPress core updates have been applied to your old site.
Next, download the latest version of WordPress and upload it to the new server location.
If your FTP allows, open up two simultaneous connections. I put the old site on one monitor and the new site on the second monitor.
Then, copy over wp-config from the old server to the new.
Now, copy over the entire contents of wp-content. If you setup and customized your WordPress properly, you won’t have to move over any other files. Some customs setups require you to move over specific files. Only you will know the answer to this.
Login to your old server’s cPanel and open up phpMyAdmin. Export the WordPress tables and compress to a tar.gz.
Open up a separate window. I usually move this window to my other monitor, where the new site’s FTP window is also located. Create a new database, username, and add the user to the database. For personal security purposes, I change the username and database name to be different than the old database.
Open up wp-config on the new server and edit the appropriate parts to reflect your new database name, username, and password. While you’re in wp-config, make sure to change the Salt.
As an added security measure, this is a good time to make sure your database prefix is set to anything other than “wp.” This will close a lot of security vulnerabilities, as “robots” scan the web for easy marks.
In your new servers cPanel, go to phpMyAdmin and import the new database. If necessary, change the prefixes on the database.
Now, you will need to run a couple SQL commands inside of the database. Without these, you’ll notice your site doesn’t function, won’t let you login, and some other weird quirks will pop up.
First – Make sure to change the “wp” in “wp_options” to whatever your prefix is set to in wp-config. Also, you may or may not need the www. This command tells WordPress where your domain is.:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsite.com', 'http://www.newsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';
Second – This command tells WordPress where your posts should point to, as they are stored as absolute URLs. Don’t forget to change the prefix.:
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldsite.com','http://www.newsite.com');
If you have links inside of your posts, they are probably still pointing towards your old server. So go ahead and run the last and final command:
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldsite.com', 'http://www.newsite.com');
That’s it for phpMyAdmin. You should be able to login to the new site with the old username and password. You may get some message about upgrading the database or clearing it out, depending on your configuration. Go ahead and do it. You aren’t given a choice anyways.
Now that you’ve logged into wp-admin, go to Permalinks settings and re-save. Your old options should still be there, but this will update your .htaccess and options.
Finally, depending on your theme, you will probably have to re-upload your header image.
If you are using plugins and some themes, you need to go into the WordPress admin panel and resave all of your options.
That’s it! Congratulations! Hey, that wasn’t so bad, was it?
March 2012 Update: This script here makes all these steps so much easier: http://interconnectit.com/124/search-and-replace-for-wordpress-databases/