This post has been marked as old. The code might no longer work. Comments have been disabled as this is no longer maintained.
I build most of my client’s sites on my server, then move it to theirs when it is time to launch. After doing it many times, I have developed a set of steps that helps me do the move quickly and with minimal issues.
First, what not to do: Don’t use WordPress’ Export tool (Tools > Export, from the WordPress Administration area). This often results in lost content and images that don’t work – they get put in the wrong uploads subfolder, making them not show up on your site.
If at all possible, you’ll want to actually move the database, make a few changes to the database, then move the server’s files over.
This should only be done by experienced developers. You can lose your files and content forever if you do something wrong, so make sure to always have a backup.
Move your database
On the server with the site you’re moving (which I’ll refer to as “old server”), find PHPMyAdmin in CPanel, Account Center, or whatever else your host provides for managing your website. Once inside PHPMyAdmin, do the following:
- On the left side, click the database that your WordPress site is using (if you’re unsure, look in your wp-config.php file at
DB_NAME) - On the top menu, click “Export”
- If this database is used only for this WordPress installation, just make sure “Save as File” is checked at the bottom and press “Go”. If you’re using the database for multiple WordPress websites, at the top-left select the tables used for this website (if you’re unsure, look in your wp-config.php file at
$table_prefix). - Note: if your table prefix is wp_ you should change it to something else. This is better for security, and also will prevent issues importing it into the new server. Here’s how to rename your tables.
That will export a copy of your old server’s database to your computer. Next, you’re going to upload the database to your new server. Log into phpMyAdmin on the new server, go to the database you’d like the tables added to, and click Import.
Update the Database
Now that you have the database from the old server on the new server, we have to make a few changes to it. We’ll be changing all the mentions of the old server to the new server.
I’m going to assume that your table prefix is wp_, that your old site was http://www.oldsite.com and your new site is http://www.newsite.com. Click the SQL link at the top to run the following commands.
[sql]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’;
UPDATE wp_posts SET guid = replace(guid, ‘http://www.oldsite.com’,’http://www.newsite.com’);
UPDATE wp_posts SET post_content = replace(post_content, ‘http://www.oldsite.com’, ‘http://www.newsite.com’);
UPDATE wp_postmeta SET meta_value = replace(meta_value, ‘http://www.oldsite.com’, ‘http://www.newsite.com’);[/sql]
- Update WordPress Options so the WordPress site knows where it is.
- Update the URL’s to the pages of your sites.
- Find any use of the old URL inside the posts (links, images…) and replace it with the new URL.
- Finally, find any use of the old URL inside custom fields (example: Thesis post image) and replace it.
Move the Files
All of your customizations to WordPress are stored in the wp-content folder, so that’s really all you need to move over. Copy the /wp-content directory from the old site and upload it to the new site. If you have SSH access you could also gzip the directory which will make the download/upload process go faster (moving one file instead of many).
Now your site has successfully been moved over. The only thing left to do is update the Permalinks and Privacy settings:
- Go to Settings > Permalinks and click Save Changes. This will create the .htaccess file so all permalinks will work.
- Go to Settings > Privacy and set the site to visible. This is only necessary if, when you first set up the site on your server, you unchecked “make this site visible to search engines”. I recommend keeping the site invisible until you deploy it.
To summarize, a Migration Checklist
- Download a copy of /wp-content and database.
- Upload database to new server.
- Find/replace domain.
- If an existing WP install is on the server, upload the /wp-content directory as /wp-content.new
- If an existing WP install is on the server, rename /wp-content to /wp-content.old. Rename /wp-content.new to /wp-content
- If a new WP install, upload WordPress to the server
- If a new WP install, delete the default /wp-content directory and upload the new one
- Update wp-config.php with new database credentials and change the SALT keys
- Log in and create permalinks (Settings > Permalinks, Save)
- Turn Privacy mode off
Aaron says
Hi
I’ve got a bit of experience with wordpress, but all of the above is welcomed advice so thanks.
I’m building a site for a client on a new server so I’ve had to assign a domain reference so I can work on it and view it etc.. When the domain is transferred everything should switch over (as it has done on a previous build). Problem is that last time all the images were missing as the file path didn’t update. For instance temp domain was http://01.100.01.100/mysite.co.uk then switching to just http://mysite.com
Wasn’t too bad last time as it was a small site with few images so just uploaded again. This time site is bigger with lots of images so want to try and save a lot of re-uploading! Any ideas how I can solve this? Thanks
Bill Erickson says
If you’re talking about the images inside of posts (technically, URLs in the database) then the above SQL query will fix all of these. If you’re talking about images in the actual theme file, use get_bloginfo(‘wpurl’) instead of hardcoding the links.
Vivek Parmar says
Nicely explained tutorial. Would be great if you upload a video. Great help for newbies
Jeff Gillis says
Bill, your php script worked like a charm, Bravo! Best to your continued success.
Jeff Gillis
jeffgillis.me
CEO & Founder
ElectricGratitude.com
toan says
any advice on moving from wordpress.com hosted site to a self hosted site since i can’t work directly with the data base and can only export xml?
thanks
Bill Erickson says
You’ll have to use the Export file. If the file is too big for export, you can either ask your host to bump up your max file size, or break the export files into many (ex: export by year, export by category… whatever gets it down below the max). I’d then recommend going through your content and ensuring all the media made it over. If it didn’t, manually add it back.
Ola Löfvén says
Great guide. I also put up a guide, and recently moved a few installations when changing webhost. Perhaps your guide is a little easier to read
Andria says
My old blog was andriapearce.com/blog, my new blog is also andriapearce.com/blog, so my URL never changed when I switched hosts. (right?) I installed the sql file and everything (including plugin theme) is showing up on the blog perfectly, except the images. I see the image names in the media library, but no thumbnails or images appear anywhere in the blog. Would following your steps solve my problem with my missing images even though the URL never changed?
My hosting company is telling me I need to change my permalinks and cant help me. So even though my URL stayed the same, something changed the links when I switched hosts? Thank you for any help, I dont know where to start!
Bill Erickson says
No, there’s no need to update the URLs if the URL didn’t change. It sounds like the images haven’t been moved over. If you FTP into your server and go to /wp-content/uploads and drill down into the folders (they start with year then month, so /2011/10 ) do you see any images?
Tim Squires says
Great information, thank you.
I developed my client’s WordPress site within a directory folder inside his domain. Is it difficult to migrate it over into the root of his domain? At present the url is:
http://www.clientdomain.com.au/subdirectory
can I migrate it into the root so that the url becomes:
http://www.clientdomain.com.au
Bill Erickson says
The above method should work just fine for migrating from a subdirectory. Copy all the files up a directory, then update the URLs in the database.
Tim Squires says
Great, thanks very much, I’ll give that a try.