How to Move a WordPress Site

Posted by on May 1, 2012 in WordPress Development | 90 comments

How to Move a WordPress Site

9/7/2012: I’ve started receiving messages from people experiencing problems moving their WordPress installations. There seem to be some new issue specific to WordPress versions 3.4.1 and up. I’ve conducted a quick experiment with one of my sites and am definitely experiencing issues with the widgets.

(0834) The widget issue is specific to the widget overrides in my RocketTheme theme. Otherwise, things are running smoothly. If you’re having difficulties, please get in touch me via the contact form and be specific about the issue you’re experiencing. As always, I’ll do my best to work with you.

I’ve had the good fortune of needing to move a WordPress installation so often that I’m discovering it to be nearly second nature. It’s not a difficult process, but it’s not intuitive either. Still, things will crop up during the process of moving WordPress from one hosting provider to another, or migrating a WordPress installation from my development environment to a production server. This tutorial will attempt to hit the high points.

Background

The first time I tried to migrate a WordPress site by brute force I made a royal hash of it. I’ve learned over the course of a number of WordPress moves that there’s a knack to doing it quickly and effectively. At this point I can transfer WordPress from one server to another, change the domain WordPress was installed under, fix the inevitable broken images in the posts, and have the site fully functional within a few hours – most of which is time spent copying files.

Before undertaking this endeavor, you should make sure that your new hosting arrangements are in place. Create an empty database at that location if necessary, and ensure that you have FTP access to the site’s final destination. For the sake of this tutorial I’m going to assume that you understand what this means and how to go about achieving it – if not, you should start by investigating your new hosting provider’s documentation in order to get up to speed.

If you are going to use Yahoo Small Business Web Hosting

Check out the post I wrote about Moving WordPress and Yahoo Small Business Hosting. I’ve had to do a few migrations of WordPress sites to or within Yahoo Small Business Web Hosting, and their administrative controls are so restrictive that it can turn into a total nightmare. Forewarned is forearmed.

WordPress Installation Migration Tutorial

Step 1: Make a Local Copy of the Existing WordPress Site Files

The first thing I do is connect to the FTP server which provides access to the files for the existing WordPress installation. In the case of a site I’ve developed locally and need to deploy I obviously have all the files already. Getting an entire site is time consuming and, with any decent FTP client, it’s automated, so I make this step one. Just connect via FTP and sync a directory on your local disk to the document root which contains your live WordPress install. Now, with files a-transferrin’, we can move on to other steps.


Step 2: Get a Dump of Your Current WordPress Database

The easiest tool to use here is going to be phpMyAdmin. Any hosting provider worth their salt is going to offer this to their users. Follow these steps to get your existing database exported:

  1. Connect to the instance of phpMyAdmin which provides access to the database for your current site. Enter your credentials to log in to the management interface.
  2. Select the database for your existing WordPress installation from the list on the left.
    Select your WordPress database from phpMyAdmin's list of databases.

    (Fig. 1) Select your WordPress database from phpMyAdmin's list of databases

  3. Click ‘Export’ at the top of the window.
    Click 'Export' at the top of the window.

    (Fig. 2) Click the 'Export' tab at the top.

  4. Ensure that the radio button for the ‘Quick’ export method is selected. Click the ‘Go’ button to download a .sql file containing a dump of your current database table structure along with all of your existing data.
    Check the 'Quick' export method radio button and click 'Go' to download your database dump.

    (Fig. 3) Check the 'Quick' export method radio button and click 'Go' to download your database dump.


Step 3: Import Your Database

Now you have to reverse the export process to populate your new database.

  1. Log in to the phpMyAdmin interface for the new database.
  2. Select the new database from the list on the left (see Fig. 1, above).
  3. This time, click the ‘Import’ tab at the top of the window.
  4. Now you’ll have to select the file you just downloaded containing your database dump so that you can upload it here. Click the ‘Choose File’ button and locate the .sql file downloaded during Step 2, above.
    Click the 'Choose File' button and locate the .sql file you just downloaded.

    (Fig. 4) Click the 'Choose File' button and locate the .sql file you just downloaded.

  5. All that’s left for this step is to click the ‘Go’ button to import your data.

Step 4: Apply Database Migration Fixes

There are two primary fields which need to be modified in order for your migrated WordPress installation to even function.

  1. Rather than browsing the data in the wp_options table, let’s just click the ‘SQL’ tab up at the top and send the Database Server Ninja Assassin Monkey Troop off to do our dirty work: Insert that SQL query in the giant ‘Run SQL query/queries on database…’ field and change the http://www.craniumstorm.com to reflect the root level of the site you’re transferring to (so, if you’re moving WordPress to www.domainfoo.com/bar make sure that the /bar is appended here).
    Click 'SQL' at the top and paste the SQL query, above, into the appropriate field.

    (Fig. 5) First, click the 'SQL' tab at the top. Then, copy-paste the above SQL query into the appropriate field and modify it to reflect your new domain before clicking 'Go'.

  2. Click ‘Go’ to execute the query. You should see a green message box saying that two rows were changed.
  3. UPDATED: Things change, and I’d be remiss if I failed to update my most popular tutorial to reflect my present methods. At this point, you’re ready to update your image URLs. Do yourself a favor, save yourself some time, and use the Velvet Blues Update URLs Plugin, available from the WordPress Plugin Directory. This plugin is so handy, and works so smoothly, that it should be incorporated into the WordPress core. I can’t imagine why you’d want to perform this step by hand, but if you’ve got a hankering for some more SQL-executin’ action, read on…

    If you’ve read some of my other stuff, you may have seen the post about fixing broken image links in WordPress posts when transferring domains. I’ll re-iterate it here to spare you having to read any more of my torturous bullshit. Now that our crack team of Database Server Ninja Assassin Monkeys has returned from their recent, successful foray, we’ve got another mission to which they’re ideally suited:

    You’re already right where you need to be. Just paste this query over the last and modify the {old url} and {new url} to reflect whatever constitutes reality in your case and then click ‘Go’ again.

    (Note: When I say ‘modify them to reflect reality’ I mean that you’ll want them to be the full significant portion of the url which needs changed. So, if you’re moving from http://www.oldfoo.com/blog to http://www.newfoo.com you’ll want {old url} to say ‘www.oldfoo.com/blog’ and {new url} to say ‘www.newfoo.com’.)

  4. Smile. You’re getting good at this.

Caveats

If you’re moving your WordPress install to the directory ‘/bar’, but you want visitors to get to it by going to ‘http://www.domainfoo.com’ (without the ‘/bar’), step 4.1 is going to be different for you. In such a case you need different values for ‘home’ and ‘siteurl’. From the WordPress Codex entry Changing the Site URL:

  • The “Home” setting is the address you want people to type in their browser to reach your WordPress blog.
  • The “Site URL” setting is the address where your WordPress core files reside.

This means that we’ve got to run two queries in the first step instead of one. The code you’re going to paste is going to look like:


‘You do not have sufficient permissions to access this page’

This will happen if you change the wp_ prefix on your WordPress database tables. Everything’s just starting to come together for you, but when you try to access your admin panels you get a box in the middle of the screen saying ‘You do not have sufficient permissions to access this page’. The WordPress Codex entry for Login Trouble has a bunch of things to try, but none of them apply to the issue you’re having. I’ll include the correct fix here:

Just replace {new prefix} and {old prefix} in the above query with the correct values for your situation. (Special thanks to Christian Schenk for his great write-up on this issue!)


Step 5: Upload the WordPress Site and Edit Your Configuration

If your files are still downloading at this point just make a cup of tea and relax for a while. Uploading the entire WordPress site is the next logical step here.

  1. When you’re ready, connect to the FTP host for the new site.
  2. Upload the entire contents of the site to its new home.
  3. Edit your /wp-config.php file to include the correct information for your new database:
  4. This has come up a couple of times now, so I’m going to say here in advance that you should try logging into the admin panel in the new location at this point. If you get in without any problems, go to Settings > Permalinks and click ‘Update Permalinks’ to make sure WordPress updates the .htaccess file. If it can’t for some reason, you should see a message reading something along the lines of ‘If your .htaccess file were writable, we could do this automatically, but it isn’t…‘ at the bottom of the admin panel. In that case, make sure that you edit your .htaccess file to reflect your current domain configuration: If WordPress is unable to modify this file automatically it’s because of a permissions problem. The best means for fixing this depends on your hosting provider, but the .htaccess file needs to be writable by WordPress.
  5. That’s about it!

Aftermath

Naturally, you’re going to want to verify that your site is working correctly before moving on with life. The only variables we didn’t address here are plugins and templates. The primary offenders I’ve found are plugin authors who have elected to store literal URLs for files in the Media Library instead of using get_bloginfo(‘wpurl’) for the URL base (if you’re such a plugin author, fix your code please).

Stay Tuned…

If you enjoyed this post or found it otherwise useful, follow CraniumStorm on Facebook to stay up to date on our latest posts.

52 comments
Ossi Mantylahti
Ossi Mantylahti

Velvet Blues plugin works fine. However you should mention in your posts that in order for permalinks to work in plain vanilla Ubuntu install, one should make sure php5-mysql module is installed. (sudo apt-get install php5-mysql).


Also in plain vanilla Ubuntu server (1404 at least) permalinks do not work as Apache's mod_rewrite is not installed by default. Jarrod Robero has great instructions here: http://www.jarrodoberto.com/articles/2011/11/enabling-mod-rewrite-on-ubuntu


Key parts:


1) enable mod_rewrite

sudo a2enmod rewrite


2) Edit default configuration file

sudo nano /etc/apache2/sites-available/000-default.conf 


Add following lines after documentroot:

<Directory /> 

 Options FollowSymLinks 

 AllowOverride All

 </Directory> 

 <Directory /var/www/> 

 Options Indexes FollowSymLinks MultiViews 

 AllowOverride All 

Order allow,deny 

 allow from all 

 </Directory> 


MohuaPolley
MohuaPolley

Hi there,


I did take back up both wp files and database. I wanted to shift my wp site to another server have same site url or domain. I installed new wp using softaculous. then replace it with my old wp core file. I have already deleted the old site after taking the backup and now new one not working.


Please help.

hiteshladva
hiteshladva

hey thanks man........ i am facing this issue since week and tired to get solutions... 

jameson20
jameson20

Thank you for this post. I was in a big problem when I had had to move my website ( http://warcraft4beta.com), because I can't really move the theme, because I edited it by manual hand, I had to copy all the text from the edited CSS files :D Yea, a bit funny, but worked, but I never get the media's content back (pictures etc). But with this method :D Thank you!

JulieDonCarlos
JulieDonCarlos

Hi Jonahs. Thank you so much for this post. I think I'm getting close but I do get a database connection error when I try to surf the site - my new files don't show up and I a m fairly certain the issue is related to ad oddity with the tables.

I use  a different prefix on my tables I notice several tables that are essentially duplicated with both prefixes for example:
myprefix_commentmeta exists but so does wp_commentmeta
myprefix_Comments exisits but so does wp_comments 

Here's the list:

  • wp_commentmeta [ed. commenter had included a link which contained sensitive info]
  • wp_commentsh
  • wp_links
  • wp_options
  • wp_postmeta
  • wp_posts
  • wp_terms
  • wp_term_relationships
  • wp_term_taxonomy
  • wp_usermeta
  • wp_users

I have no earthly idea how I accomplished this ;-) but I can tell you it is 95 degrees right now!! Can I just "drop" these tables. Hope I haven't made a bigger mess. Thank you again!

NiajMorshed
NiajMorshed

I moved a wp site to another address, everything is ok without the site-name, I tried to change the site title using  dashboard->appearance->customize its work for all even in dashboard->settings-> general, the site name is changed, but in front page the old site name still present, how can I solve this?

MaudWard
MaudWard

I have tried this three times, following your instructions exactly, and every time I try uploading my old database to the new server, I get the error message "#1044 - Access denied for user 'millage'@'localhost' to database 'db473473645' . One thing I am wondering is about the "new database" on the new server you mention. Do I have to create a blank one with nothing in it? As I installed wordpress on this new server, and I am selecting THAT database and attempting to upload. I'm not sure what else to do.

helz123
helz123

I can't thank you enough for this article - it saved a lot of time when things were getting a bit "ranty"! It's going on the blog now everything's working properly. Thanks again!

jrmb23
jrmb23

You saved me a TREMENDOUS amount of work.  I had been trying to do this for days and days and your site guided me perfectly through it.  THANK YOU SO SO MUCH!!!

Jean Francois Garcia
Jean Francois Garcia

thanks for this tutorial.

I have move my site to an other server, all seems good, but I can't access to the admin panel after login.

The "Red section" if the only one I Haven't done. I apply it and Now, all is ok !


Thank you for this job ! I'll put this page in my favorite, for a future problem ^^

stevedovey
stevedovey

Thanks sooo much, you just saved me hours of work and a mountain of stress!!! I was dreading this as I've had a couple of WP moves bomb on me badly. This went so smoothly. About the only that didn't go 100% according to plan was a few image referrals but those shouldn't be hard to fix.

Qwaerstd
Qwaerstd

Hi 

Thanks for your post. I've used this technique before with success but this time I cannot seem to get the image links to update. 

I've used UPDATE wp_posts SET post_content=(REPLACE (post_content, '{old url}','{new url}')) and tried the old and new urls both with and without http://www.,trailing slashes and wp-content/ at the end but nothing seems to make a difference. I've also tried logging out of WordPress and back in, and have been through the whole process twice.

Does anyone have any suggestions? Thanks

rananjason
rananjason

Hi. I, actually, reinstall my website after defacing attack. I decided to change 'SITEURL="www.domainname.com/secret_folder"' to point to a different folder.

The problem is on the dashboard, I don't see my older posts and pages otherwise on phpmyadmin, I can see all of my publication.

Can you help me howto fix this?

golena
golena

I was terrified of moving my wordpress site to the new domain (and new hosting).  Your tutorial was perfect and everything transferred beautifully. Just had a few image links that had to be updated on the new  site.    Thank you, thank you!!

mamta108
mamta108

Thanks for this.  I'm having a problem still, though.  When I try to loginto my account live on godaddy (name of site.com) it routes me back to my log in for my virtual hosting site desktop server (name of site.dev).  There must be some file that I can change this simple script for...  I thought it was mysql file, but that is all correct.  Any help would be greatly appreciated.

merk
merk

Hi, thank you for a great post. it seem very simple, I just wonder what will be the steps if one wish to test the new site before changing the DNS..

DodgeIntheshed
DodgeIntheshed

Thanks for that  jonahs,Apart from the slight problem with the DB (see below), it worked a treat.

Dodge.

DodgeIntheshed
DodgeIntheshed

Hi jonahs,When I try to import my database, Im getting this error:

SQL query:

-- -- Database: `echographicsonl` -- CREATE DATABASE `echographicsonl` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;

MySQL said:

#1044 - Access denied for user 'echoadmin'@'localhost' to database 'echographicsonl'Can you help?Thanks, Dodge.

 

daniel_dropik
daniel_dropik

Thank you, this may help. Can the process described above work when I am trying to move my WordPress website onto my local workstation( which I will be using for testing the site "offline") ?

BrianWhitton
BrianWhitton

Thanks. Great tutorial. I was reading WP's tutorital but got a bit confused as to when to edit databases and such.

 

I didn't need the old blog to work, so before I exported the database from my original server, I used the safe search and replace script at this site: http://interconnectit.com/124/search-and-replace-for-wordpress-databases/.

 

It updated all instances of www.devserver.com/client to www.clientsite.com and fixed it for serialization issues.

 

Then I was able to skip step 4. Very handy!

BtrBetaTrading
BtrBetaTrading

Awesome tutorial! Aside from a minor user error on my part, it worked flawlessly. Thanks so much for sharing the knowledge.

Jan Bear
Jan Bear

You saved my life with this tutorial. Thank you.

sarahbbrand
sarahbbrand

You are a hero of the internet. One thing I might add is that if someone does this and is getting "500 Internal Server Error" messages at all, manually checking the .htaccess file is useful even if Wordpress was able to update the permalinks automatically... for me, Wordpress just appended a second set of rewrite rules to the bottom of the .htaccess file, so the rules referencing the old site were still there.

tempestuality
tempestuality

Great tutorial! Thanks for writing it :) I am installing an extension for Magento to integrate it with WordPress (FishPig WordPress Integration). So far that is going well. However, it states that:

                        It is recommended that you install WordPress in a sub-directory of Magento. Do not install it in a sub-                             directory that you plan to make your blog visible on.

My Magento install is on my root directory, and WP is in a subdirectory, and in violation of the above since it is installed in the directory it is visible on. So I made /wp for it and need to move it there but still show it at /blog. I followed directions on the codex for giving wp it's own subdirectory: 1) make subdir 2) wp-admin/ general set site url to the /wp and home kept same for /blog (full url entered) 3) moved all files from /blog to /wp, 4) copied back over the index.php and .htaccess 5) edit /blog/index.php entry to require('./wp/wp-blog-header.php'); (was without a subdir originally), was able to sign in, but here is where I am stuck, got sign in, but then got errors. Basically it is looking for header file in blog/wp/. So I tried going from the entire file structure /home/my username/my site/wp/wp-header, and no. Tried without the / in front of home and no, it is still rendering that inside of /blog. I am unable to find out how to make it go up one directory, or change directory to /wp. In the example since it is coming from the root to a subdirectory in the root (blog is shown on example.com, db located at example.com/wordpress) I think that is why that example works. I am having difficulty in finding any answers on moving from subdirectory to another subdirectory. I will search more and if I find a solution, I will reply so you know.

 

Oh, and since I am just changing from one subdirectory to another do I need to make the sql entries above and/or update the Permalinks?

 

Thanks, 

Kelly

SamirKhanal
SamirKhanal

@MohuaPolley connect me in s k y p e - at - d r e a d t h u g

I am a wordpress freelance, I may be able to help you.

jonahs
jonahs moderator

@JulieDonCarlos You may have forgotten to edit your wp_config.php file. There's a line in there which, by default, says:

$table_prefix = 'wp_';

That needs to be changed if you're changing your table prefixes.

Stay cool!

jonahs
jonahs moderator

@NiajMorshed Boy, WordPress plugins and themes can be pretty quirky in terms of the way they store things. If that title is coming out of the database, it's got to be coming from somewhere other than the actual site title. Try getting a database dump in phpmyadmin and searching the dump in Notepad+ for the old site name.

MaudWard
MaudWard

I created a new empty database for the dump from old site, still exact same error message.

JakeHarris
JakeHarris

I ended up doing it the old fashioned way: running a ctrl+h on the .sql file. In my particular case, it looked like this:

Replace: old.development-server.com

With: newdomain.com

Good luck :)

rananjason
rananjason

Finally, I retrieve the problem. I omit the right table prefix o wordpress, so the new destination installed a new database!

jonahs
jonahs moderator

 @mamta108 On its face, I'd say that this sounds like a home URL/ site URL issue as described in step 4.1, above. However, assuming that you've completed that step successfully, I'd suspect that there's a redirect occurring in either your index.php or .htaccess file. Please use the contact form to reach me if you're still not having any luck.

jonahs
jonahs moderator

 @merk I'm afraid that I may not be understanding you. Do you want to test the DNS changes before actually moving the site?

DodgeIntheshed
DodgeIntheshed

Sorry jonas,My mistake,I had to go back to the old database and change the Character Set to utf8!!!

jonahs
jonahs moderator

 @daniel_dropik Absolutely, Daniel. In essence, anywhere I would have 'www.craniumstorm.com', I would want to replace it with 'localhost'. Use the contact form to reach me if this is confusing, or if the process goes south on you!

jonahs
jonahs moderator

 @sarahbbrand If I have seen further, it is by standing on the shoulders of giants. Still, thank you kindly. Also, thank you for sharing your experience. A couple thousand people a month are now coming to read this article, and you've certainly helped some of them.

jonahs
jonahs moderator

 @tempestuality you answered at least part of your question at step five: './wp/wp-blog-header.php'that leading period tells the server that the '/wp' directory it's looking for is a subdirectory of whatever directory it's currently working in. therefore: if the file is /blog/index.php, a reference to ./<anything> from a file within that directory will use /blog as its base. getting rid of that period will make it '/wp' where '/' is the document root =)now, as to whether you need to run the sql above... if you've moved an existing wordpress installation to any url other than the one at which it was originally installed the answer is yes. make the change above and give it a shot. use the contact form to get in touch if you're still having issues. 

jonahs
jonahs moderator

@MaudWard 'Access denied' is pretty straight-forward. It's an error generated by the database itself, and there are a very few things which might case it: 1.) bad username, 2.) bad password, 3.) invalid host, or 4.) the user lacks the privileges to perform the requested action. We'll assume that you are using the proper user and pass.

Go to the 'Privileges' section and make sure to grant full permissions to the user 'millage', and make sure you're specifying the appropriate host. So, 'localhost' is only valid if your web server and database server are on the same IP address. It's often enough the case that they're not, so you'd want to make sure to use 'millage'@'<your web server address>'.

The way to fix this might depend on your hosting provider. Take a look, and if you find yourself lost you should feel free to get in touch with me via the contact form.

NiajMorshed
NiajMorshed

please check the exported file is in .sql extension not in .sql.zip which you want to import.

jonahs
jonahs moderator

@JulieDonCarlos Please contact me privately via the Contact Us link, and we can discuss your configuration in more detail.

RyanHolt
RyanHolt

@jonahs @MaudWard @DodgeIntheshed I had the same issue, so instead of using phpmyadmin to export the database I used backup wizard to create a backup of my database which i then restored onto my new server. Sometimes it can depend on your hosts settings if you are able to import databases so the backup wizard is a workaround.

Trackbacks

  1. [...] For the purpose of setting up a local environment for testing things out, this may not matter. But if you want to update all the links within blog posts as well, instructions can be found in some of the articles linked from here such as this one. [...]