Moving WordPress to a new domain or server

WARNING! This post isn’t really for beginners. In any case, please back all your stuff up comprehensively before trying anything out. If you don’t know what you’re doing, things could go quite wrong.
Moving WordPress’s location—be it to a new domain, a new server location, or both—has never been as easy as it might be. Here I’m going to document my own process for achieving this, and try to keep it updated with new ideas and lessons learned.
Please note before starting that I’m concentrating here on the WordPress-specific side of this process. For anything not related to WordPress regarding moving domain or server, you should probably check with your domain registration service or web hosting provider.
1. Lock out all users
Firstly, you should prevent any users from accessing the site. This is so you don’t get any content / comments / etc. submitted after you export the database.
Generally I’m in the situation where I have to move a WP installation from a development domain to a live domain, so this has little impact; but it’s worth doing so anyone adding content (e.g. your client) doesn’t lose work.
If you’re moving a live site, you might be looking at a bit of down time. I won’t be going in to the more general ins and outs of moving a live site for now (sorry!).
There are probably, ooh, umpteen ways of locking users out elegantly. My preferred method is using my 503 holding page, with a filter for my own IP address. If you’re not comfortable with .htaccess the Maintenance Mode plugin should help.
2. Back up files
If you’re moving the location of your files on your server, you’ll need to pay attention to this. If you’re just changing the domain, you may as well back files up, but it’s not necessary.
You can be blunt about this and literally back up all files, but really these are the only WP files that are unique to particular WP installations:
/wp-content/(everything in this directory)/wp-config.php
While not standard WP files, these are common files that might also be specific to your installation:
/.htaccess/apple-touch-icon.png/favicon.ico/robots.txt
For any of my clients using my installations, these files also need saving:
/503.php
See also: A more detailed guide to WP files.
3. Back up the database
The database contents have to change whether you’re moving server or domain.
You can do this using the WP-DBManager or a similar plugin, or via phpMyAdmin (accessible through your host’s control panel).
Here’s a sample phpMyAdmin Export screen showing typical options you’ll need to select:
4. Back up any complex plugin data
For me, this means exporting all stuff from the excellent but fiddly cforms plugin. Back up each individual form, and all the global settings.
5. Make file changes
Do a global search through the site’s files for instances of the absolute server path and/or the domain. Most good editors can search through multiple file contents. I know Dreamweaver does; personally I use TopStyle.
Until you’re familiar with the process, it’s best to check each instance before replacing it.
Replacing the server path
Here’s some places where you might find the absolute server file path if it needs changing:
/.htaccess(I usually have some.htpasswdprotection ready to roll just in case, and the path to that file will be here.)/wp-content/plugins/cforms/abspath.php(If you’re running the cforms plugin, this file sometimes needs to be created manually, containing a reference to the server path. Why? Good question. In short, it’s related to AJAX.)
Replacing the domain
Here’s some places where you might find the domain if it needs changing:
/.htaccess(I usually have a bunch of things in here that need the domain hard-coding: redirects, rewrites, no-www stuff, etc.)/robots.txt(For me, usually a reference to the XML Sitemap.)/wp-content/plugins/cforms/js/cforms.js(More AJAX-related fiddlyness from cforms.)
6. Make database changes
Here’s where the fun starts!
I’m joking, this bit’s a nightmare. At least, it can be a pain.
You’ll probably need to alter the database contents for any server or domain change.
Character encoding
I still occasionally make a mistake here, but basically you need to check if your database tables are set to UTF-8 or not. If they are, make sure you do any editing of the database export file in an editor that supports Unicode files. I know the latest Dreamweaver and TopStyle do. TextPad does; I think even Notepad does these days, so this might not be as much of an issue as it used to be. (Though Notepad is probably best avoided. Its search/replace won’t be up to the task here, and my experience of it working with multi-megabyte files is patchy.)
I’ve not tried any of these solutions out, but the ace WP developer Vladimir Prelovac has a page and a plugin aimed at solving problems with UTF encoding in WordPress databases.
Anyway, because of character encoding and for other reasons…
Keep an unchanged copy of your original database backup file
We’ll be editing the SQL file your database backup produced, but it’s best to keep the raw, unedited original intact. Make a copy and make changes to that for the new database. Just in case…
A problem: serialized data
The thing that turns doing a “simple” search/replace on our SQL file to switch the server path or domain is that WP, and some plugins, often store settings in the database using serialized arrays.
What’s important here is that this data format will store, alongside a string of characters, the length of that string. If you change the string to something of a different length, it won’t match the stored length, and the data will be “corrupted”. Plugins like cforms include a function that tries to help out if this happens, but my experience of it isn’t reassuring.
I recently found a PHP Serialization Fix for WordPress (by Dave Coveney). Dave offers the code with caveats. I’ve not had time to test it out yet, so even though it’s a PITA, for now I’m sticking with the manual method below. It is possible, with a little patience.
- Open the copy of your database SQL file in your editor.
- If you’re changing the server path, do a search/replace to switch the old absolute file path with the new one.
- Scan through the list that your editor gives from the operation, and look for replacements that look like this (only surrounded by loads of other data, obviously!):
s:17:"/new/server/path/"The
sat the start there indicates that in the array this data was serialized from, this value is a string. The number that follows is the length of the string, then you get the string itself. You need to change that number to the length of the new server path for each instance where you can see that it’s been changed in a serialized array. - If you’re changing the domain, repeat the above two steps for the domain.
- Save the file and exit the editor.
My experience is that the number of instances stored in a serialized array where the string lengths need changing, for either server path or domain, isn’t unmanageable. The contexts where either are stored many, many times, are usually not in serialized arrays. A common example is where the site’s content is packed with URLs—either image tag src attributes or links. You may get oodles of these, but the straight search/replace will have dealt with them OK; they’re not in serialized arrays.
7. Get the new site going
Now you’re pretty much set.
- Import the altered database SQL into a new database (you may as well keep the old one installed for now as an extra backup).
- If any database information (name, user, password or host) is changing, update the new site’s
wp-config.phpfile appropriately. - If you’re moving the files, upload them to the new location. If you’ve only backed up the installation-specific files, upload the other WP core files as well, taking care not to overwrite any of your customized files (especially the
/wp-content/directory). - Do whatever you need to switch the domain over, change the DNS, etc. I can’t help you with this bit if you don’t know what to do—ask your server admin.
- Test the new site before removing whatever method you used to lock other users out!
- Check your cforms if you use that plugin. If your data didn’t make it through the changes, you can just reset the plugin and import your backed up forms and settings.
- If you’ve moved your files, you might need to check file permission-related areas such as:
- WP / plugin upgrading (see this post)
- The
/wp-content/uploads/folder (see this Codex page)
I hope this has all been of some use to you. While I can’t provide support for basic issues, and certainly wouldn’t recommend a beginner trying all this, please let me know any better ways you have of addressing the same issues, helpful plugins, corrections, etc. Thanks!

Welcome! I build websites - mostly based on the brilliant, free & open 
Charlotte (16th December 2009)
Worked like a charm. Thank you so much!
Steve Taylor (16th December 2009)
Glad it did the trick!
Devon Woods (22nd December 2009)
Hey Steve! I have been looking for some instructions like this but I want to be sure it will work for my situation which is …I currently have a blog at [URL removed]. I just purchased the domain [URL removed] and it is pointed to the same name servers as my [URL removed] domain. FYI …I created [URL removed] as an addon domain at [URL removed]. If you are not familiar with addon domains …An addon domain allows you to reach a sub-domain when entering the name of the addon domain into a browser. This means that you can host additional domains from your account, if allowed by your hosting provider. Addon Domains are relative to your account’s home directory.
Will the above process work for me to move [URL removed] to [URL removed] ? or would the procedure need some slight modifications to work for my situation?
Thanks, Devon
Steve Taylor (23rd December 2009)
Devon, in brief, the above should work for you, but I can’t make any guarantees – it’s all very “as-is”.
I was in two minds whether to spam you though. Watch out when you post super-simple questions infested with repeated URLs!
Huken (3rd January 2010)
Thanks this post! I want to move my blog to new server…
Yann Lorber (21st January 2010)
Hello, thanks for the help! But me I had another problem, it was not the number of characters but the conversion of single quotes to double quotes. I had to do it manually because the solution by Dave Coveney didn’t solve my problem. Bye bye
Brandon (18th February 2010)
Hello, do you have a “how to” video guide to follow? I am a complete newbie and I want to change my domain name and reading the above really confuses me. Any extra help would be awesome.
Thanks,
Brandon
Steve Taylor (19th February 2010)
Brandon, sorry, I’m too busy. Do read the warning at the start!
Peter Moss (19th March 2010)
Hmm, I went through similar headache moving from blogger to blogengine. I think key is to know your indexed links before the move, setup 301 redirects on new home.
Peter
Onno Marsman (7th May 2010)
People who are interested in this post might also want to take a look at the ezMigrate plugin for WordPress.
gale (22nd July 2010)
hi,
i got this problem. I have a blog which i transferred to a different server but same hosting company. the blog was under a subdomain previously and now i’ll be assigning it to a domain. I have already updated phpmyadmin under wp_options, change the URL. already udpated my wpconfig.php pointing to the right database. The things its pulling up a previous permalink which I use previously (the subdomain.domain.com) I’m quite confuse, what I mess up and I dont know how to have this work. Please let me know what to do.
Steve Taylor (22nd July 2010)
Gale, have you searched the database in phpMyAdmin for the old subdomain? You need to replace all instances of it with the new domain—but mind out for the problems described in section 6 of this post. Good luck!
gale (22nd July 2010)
I was able to place my site, but images are not showing up. Its pointing from a previous path, is there a way to point it to the updated path?
Steve Taylor (22nd July 2010)
Gale, I’m guessing the images aren’t showing up because their URLs (in the
imgtags’srcattributes, in thepost_contentfield of the posts table) are still pointing at the old domain. You need to replace every instance of the old domain in the database (in every table) with the new domain. As I said, though, note the caveats in section 6 above.