Migrating WordPress to a different domain or server
Source: http://michael.biven.org/2008/01/31/migrating-wordpress-to-a-different-domain-or-server/
All credit and copyright goes to the above site:
Two common questions I see both at work and from friends is how best to migrate a WordPress site from one server to another or how to go about changing the Domain Name. There are four different scenarios that will affect the changes you would be making:
Changing the Domain Name only or in combination with one of the scenarios below
Moving from one self-installed server to another self-installed server
Moving from a self-installed server to WordPress.com
Moving from WordPress.com to a self-installed server
Below are the steps that I suggest including backups, starting DNS changes, configuring the new server, database import and changes, verifying the new server, final DNS changes, 301 redirects and final verification. I will point out which applies to each of the different scenarios and also briefly go over a few tools that can help at the end of the guide. Remember though I don’t expect anything bad to happen this guide is completely use at your own risk and I do not take responsibility for anything resulting from following them.
Backup:
(applies to all four scenarios)
The very first thing to do is make a complete backup of the existing site for a few different reasons. First if you really do care about the work and effort you are putting into your site take the extra time to backup it up on some sort of regular schedule. Next is that we are about to make changes to the site and you will want a recent (as in the day your making the changes) backup to fall back on just in case something goes awry. And if you are moving from a self-installed copy of WordPress to another you will already have a copy of the plugins, themes and uploads to copy over to the new server. You do already have a current copy of WordPress and any plugins you have installed right?
So now on to backing up your site. I would suggest that you follow Lorelle’s guide to create a backup for WordPress and keep in mind the XML export would be needed if you are migrating from or to WordPress.com.
First set of DNS changes:
(applies to all four scenarios)
Try to make the following changes in DNS at least 24 hours before you plan to switch to the new domain name or server. Drop the Time To Live (TTL) for the A record that the blog uses down to something like 300 (make note of it’s original setting since you will need to change it back later). The TTL is in seconds so the 300 is equal to 5 minutes. During the migration to the new server you will be getting a new IP address, this way the TTL is dropped and since you made the change at least 24 hours before your migration you should only be looking at a 5 minute hiccup during the switch to the new server.
Configuring the new server:
(applies to all four scenarios)
Next on the new server go ahead and complete the basic install of WordPress. If you are moving to WordPress.com configure the new site, keep it set to private, but do not enable the domain alias at this point (under Options > Domains). For self-installed copies of WordPress depending on what type of access you have with the server you may need to edit your hosts file on your local computer to complete the install since you do not have DNS pointing to the new IP address, specifically when you run the file wp-admin/install.php.
Importing the data:
(applies to all four scenarios)
Now that we have the basic WordPress site completed it is time to import the data (posts, comments, pages) into the new server. Remember if you will be changing the Domain Name as well you will need to make the necessary changes in two tables in the database which I will go over at the end of this step.
If you are moving from one self-installed copy of WordPress to another use the backup of the database to create a new database on the new server. You will need to recreate the database user and edit the file wp-config.php to reflect any changes in the database name, user and password.
If you are moving to or from WordPress.com you will only be able to import the data to the new server from the XML export you created earlier. From the dashboard at the new WordPress.com site go to Manage > Import and then select WordPress. You will then be prompted to browse to the location of the XML from the previous export. Also when importing the file you will be asked if you want to change the author for the posts and drafts you are importing.
If you have changed the domain name used for the site and used the database backup to import your data you will need to make changes to two different tables. We need to change the Blog Address (URL), WordPress Address (URL) and the GUID for the posts. The Blog Address is listed as siteurl in the field option_name and the WordPress Address is home in the same field. You can use either phpMyAdmin or mysql if you have shell access, but the examples I give will be using phpMyAdmin.
The first two fields are located in the tables jl_options. After logging into phpMyAdmin click on the name of the database in the left hand side (you will need to select it form the drop down box if you have multiple databases) and then click on the SQL tab at the top of the page. In the “Run SQL query/queries” text box enter the following and press “Go” to change the Blog Address (URL):
UPDATE jl_options SET option_value =
replace(option_value, 'http://old.domain.com', 'http://new.domain.com')
WHERE option_name = 'home';
And to change the WordPress Address (URL):
(remember if you have your WordPress files in its own separate directory this URL will be different than the Blog Address)
UPDATE jl_options SET option_value =
replace(option_value, 'http://old.domain.com', 'http://new.domain.com')
WHERE option_name = 'siteurl';
To update the GUID with the new domain name enter:
UPDATE jl_posts SET guid = replace(guid, 'http://old.domain.com','http://new.domain.com');
And for any links to other pages or posts internally in your site with absolute URLs:
UPDATE jl_posts SET post_content =
replace(post_content, 'http://old.domain.com', 'http://new.domain.com');
Now that we have the data over get your theme and any plugins that you will be using configured on the new site.
Checking our work up to this point:
(applies to all four scenarios)
At this point you should have the new site up and running on the new server, but before we make it live by updating DNS with the new IP address or enabling the domain alias in WordPress.com you should take a moment to verify (thanks to the edit to the hosts file) that everything looks and behaves correctly. Consider viewing the site both while you are logged in as an admin and while logged out. You won’t be able to view a WordPress.com site while logged out unless you create a new user account and grant it permissions to access the site under Options > Privacy.
Final changes to DNS:
(applies to all scenarios)
After you are satisfied with the new install make the final change to DNS by either changing the A record or enabling the domain alias in WordPress.com. The changes for the A record includes updating it with the new IP address and changing the TTL back to it’s original setting.
301 redirects:
(applies to scenarios where the domain name changes)
So you just changed the domain name for the site and you might be asking yourself what about any links to the old domain name that are still getting spit out by search engines. You can take care of this with a simple .htaccess file in the root of your old domain names web server. Simply create or edit the file to include the following:
RedirectMatch permanent (.*) http://new-doamin.com$1
This will send any links to the old domain to their corresponding page at the new domain name as long as you do not make changes in the permalink structure. The longer you can leave this the better, but you should start seeing search engines updating with the new link, because we used a permanent redirect.
Final checks:
(applies to all scenarios)
It would be easy to think you’re done and stop right here, but I would suggest a couple more checks. Though you might have to wait a few hours or a day depending on how you made your DNS changes, take advantage of Google’s Webmaster tools, the Feed Validator, or Yahoo! Site Explorer to verify your sites robots.txt, sitemap, and any errors that they encounter with your site or feed. Also keep an eye on your bandwidth after the change just in case you have misconfigured something that is causing any problems with the site making calls to itself (ie using the RSS widget to load its own RSS feed) or anything else that we might not think of at the moment.
Closing and additional tools to help:
If you are planning on moving your site I hope you’ve found this guide useful, good luck and enjoy.
A few additional tips to help you check things as you go or troubleshoot (hopefully not) any problems.
Flush your local DNS cache:
In addition to making the changes in your local compuaters hosts file you may need to clear out your local DNS cache.
Mac OS 10.4 and older:
lookupd -flushcache
Mac OS 10.5:
dscacheutil -flushcache
Windows XP and newer (might work on Windows 2000):
ipconfig /flushdns
Query DNS servers with dig:
Being able to query the DNS server you are using or others is another handy skill to have when your mucking around in your sites DNS. On a Mac running OS X or Linux you can query your’s and other DNS server to see what they have listed for your domain using dig.
check your current DNS server for the A record
dig domain.com
check your current DNS server for the MX record
dig domain.com mx
check your current DNS server for the A record on a subdomain
dig sub.domain.com
check a different DNS server for the A record
dig @DNS.server.com domain.com
check a different DNS server for the MX record
dig @DNS.server.com domain.com mx
check a different DNS server for the A record on a subdomain
dig @DNS.server.com sub.domain.com
Comments
2 Responses to “Migrating WordPress to a different domain or server”
found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later ..