post-page

Moving Your WordPress Site and Database

44
responses
by
 
on
April 3rd, 2010
in
HOW-TO, WordPress, WordPress FAQs, WordPress Tips

There comes a time you may have to leave one web host for another. No matter the reason the idea of relocating an entire website – especially one that has been online for sometime – can seem very daunting. With a WordPress based site – I found it easier than expected – way easier.

My WindowsObserver.com website has 1,100 posts, 9 pages, 4 categories, 2,436 comments, uses 17 widgets, and has 35 active plug-ins. On top of all those elements I use Windows Live Writer to create all of my content and I use a good bit of screenshots and graphics in my posts. As a result I have over 40MB of images (1,100 files) to go along with my 1,100 postings.

Now for the purposes of this story I am not going to get into a comparison of hosting services or the like. The landscape is massive out there and confusing enough. You do not need me adding to it here :-)

I will also make a few other caveats/assumptions:

  • This is also based on a self-hosted WordPress site. I am not sure if this works on WordPress.com. If anyone has tried it please comment.
  • That you know the basic workings of a WordPress site such as plug-ins, directory structure, etc.
  • That you have FTP access to your host and therefore your WordPress files.
  • That you have access to your host to create the database and user account details for it. I will talk about phpMyAdmin because that is what my host uses. You may have a different way to access/create your database.
  • That you know how to update your websites DNS info with your new host so that people can find it at its new location.
  • I will only talk about one WordPress backup plug-in and that is WP-DBManager by Lester Chan. I know and understand there are others out there but this is what I used.

So with all that said here is how I dealt with a move between hosts:

  1. I backed up my current sites database using the WP-DBManager plug-in. If you use the defaults for the plug-in the backup will be stored in a sub-directory of the /wp-content/ directory called backup-db.
  2. I then launched my FTP software and downloaded the entire site to a temporary folder on my hard drive.  You need to make sure you grab the entire structure of your WordPress site.
  3. While the download was happening I went to my new host and created a new MySQL database and user. You could always use the same details as your old host but sometime the prefix for the database name can not be changed. I recommend a fresh database name and password just for good security practices. Make sure you also get the name of the database server. You will need all of this data to get your WordPress site working on the new host.
  4. I then created my domain at the new host using their control panel. At this point I did not do anything with DNS. Don’t worry though – creating your domain at the new hosts will do nothing more but prep a directory for you to access and upload your files to.
  5. After the files were downloaded from my old host I placed an index.html file in the old sites main directory with a simple message that the site was being relocated. You can be as fancy or in depth as you want.  I then named my WordPress index.php to index.bak so there are no conflicts between the two. This also comes in handy as the DNS shift happens because people will see your site in its new location or the moving page. Once they no longer see the moving page then they will be good to go on the new location/host. It is a great tool for seeing the DNS shift in action.
  6. I then updated my wp-config.php file on my local hard drive to reflect the database information for the new host. if you have set up a WordPress site before you know how to do this already.
  7. Now it was time to upload all the files to my new host from the local hard drive keeping the exact same directory structure.
  8. Once the files were uploaded I updated my registrar’s DNS info for the new host and location of my site.

They say a DNS shift can take up to 48 hours to propagate around the Internet and your mileage may vary for how quick you see the update yourself.  About 30 minutes after I entered the new DNS info at my registrar I flushed my local machines DNS info and was able to see the site at the new address at that point.

To flush your DNS you need to open a command.com window and type in “ipconfig /flushdns” without the quotes. If you then ping your websites URL and see it reply back with the new hosts IP address then you will be able to browse your site at its new location once everything is setup there. If it comes up with the old hosts IP address then there is nothing you can do but wait for the DNS update to get around.

Now for the database move/restoral.  Some hosts restrict the size of files you can upload so you need to be aware of that for your host in these next steps. However, I am going to provide two options for restoring your database. One takes a working knowledge of phpMyAdmin or a similar MySQL database interface – the other makes use of the WP-DBManager plug-in to restore the database and site.  The plug-in method can be used for small size databases as well as large ones.

Restore your database using phpMyAdmin or similar MySQL database interface:

  1. I logged into my host and from the control panel I accessed phpMyAdmin logging into the interface using the credentials I created for the sites database.
  2. I then went to the Import tab, browsed to the temporary directory on the hard drive where my WordPress site files were stored and went into the /wp-content/backup-db/ directory to find the backup copy of my latest version of the database. Once selected I then left everything at its default settings and clicked the Go button to import the database structure.
  3. That is it – the database is now present on your new host in the new database. If your DNS is updated and everything is uploaded you should be able to type your websites address in a browser and it will come up just like it did before the move.

Restore your database using the WP-DBManager Plug-in:

In order to use this method your DNS has to be moved so you can access your site at the new host.

  1. Browse to your websites address and you should be prompted to create your new site just like when you do a fresh install of WordPress. Type in your sites title and your email address and then go the the next step. You will be provided the temporary password for the admin account.
  2. Log into this WordPress install and then activate the WP-DBManager plug-in. Do not worry about activating other ones. Then use this plug-in to restore the copy of your database that should have been uploaded to your new host with all the other files. It will be in that /wp-content/backup-db/ directory.
  3. Once that database restores your site will be up and running with plug-ins activated, the same theme, etc.

You will likely still need to tweak a few things like file and folder permissions but if you got the entire directory structure uploaded and restored the entire database your site will be there just like on the old host.

As always, your comments about your own experiencing in this process and the tools you used are always welcome – in fact we look forward to them and the community sharing your unique experience. There is always someone else out there looking for similar info.

heading
44
Responses

 

Comments

  1. infmom (8 comments.) says:

    I recently had to go through this when I needed to upgrade to a newer version of MySQL so I could update WordPress. The WP-DBmanager plugin worked as you say, but somehow, instead of period-and-spaces, I got  all over the posts. No idea how to fix all that, so I mostly left it alone and used a plugin to put an explanation at the bottom of each post.

    • Richard Hay (14 comments.) says:

      You might try the Search REGEX plugin – might allow to search and replace those characters in the database. Make a backup though just to be safe.

      I used the Search REGEX plugin to replace an old ad format shortcode once and it worked well.

      • infmom (8 comments.) says:

        Thank you. I’d never heard of that plugin before, and it looks like it might do the job.

  2. Alexandra (1 comments.) says:

    I have a feeling this may come in handy one day ;-)
    Thanks!

  3. Edward de Leau (1 comments.) says:

    I have moved quite a lot SEO technically not smart then again for a private blog: who cares :)

    a) I have moved from other blog system to WordPress (losing all comments)
    b) I have moved from different domain names to other domain names
    c) I have moved from different domein names to other domain names AND put all the pages on another root+gave them another name

    1. I would not use an automated export but a manual one, since this is the most excellent opportunity to finally kill
    those dozens of tables left over from long-gone plugins (e.g. the e-commerce things, trackers, etc…).

    2. It takes the same approach though you need to scan the exported SQL file for your old domain name and make the necessary changes (assuming you know what you are doing and not kill the options table). Just look for every “hit” (and previous
    names if you moved before) and analyze the patterns, you will get a handful of replacements that work overall. Those
    handful of replacements might be handy to blog about another time since they are always the same. Maybe you can at the same
    time kill some entries in the options table.

    3. After loading it in I had many pages on a different location / root, so that was easier done with SQL queries in the wp-post table then by using regex on the sql file (i take the easiest way SQL is much easier) (DreamCoder is FREE
    and a real nice SQL tool to run it locally and connect to your external SQL databases) (so for the hardlinks inside
    the posts themselves !!)

    4. For some remaining “other site + other page + other name of page” things I added some lines to the .htaccess of the current site

    5. Because many things ended up at different permalinks I choose to .htaccess redirect EVERYTHING to the ROOT of the new site and then have the special cases handled and do some logging for some time to see if I forgot something.

    6. Since the comments are pretty much not recoverable if the old pages are gone (i generate them via xmlrpc from my localhost db) I well… lost all the comments on the pages (but no the posts) before I also lost them when I moved from my own
    written blog tool to WordPress (I still have them hoping I have a brilliant regex idea some day).

    7. Conversion to unicode tables … takes a 2 step approach

    8. I learned that it is mostly done in a hurry while if you think and make a plan before doing it, it will save much time instead of doing it and repairing afterwards.

    I now want to move from WPMU/BuddyPress on Apache to WPMU/BuddyPress on Nginx, so let’s see if that goes without any problem (and I HOPE upgrading to WP3.0 FROM WPMU …. will go with not much pain incl. all the self written code).

  4. Hikari (26 comments.) says:

    Just backup the whole database and wp-content, and then restore.

    For changing the site URL, u must go to database’s wp_options and edit rows ‘siteurl’ and ‘home’.

    Then u’re ready to move everywhere u want.

    • Dave says:

      Yeah, this is the method I’d use. Do a fresh install of WP, just migrate the DB and wp-content folder.

  5. Ryan Erickson (2 comments.) says:

    I couldn’t ask for better timing with this piece… just last night I started shopping around for a new host- and thought I’ve moved before my site has gotten a little bigger so it’s nice to see a walk-through and with the same plugin I use. Thanks a million!

  6. Flick (28 comments.) says:

    I’m a big fan of Lester-chan’s WP-DBManager plugin as well.

    Am now working on a local version of a revamp and decided to opt for exporting of posts/comments (in several batches using WordPress Advanced Export) into a new WP installation and exporting the relevant tables for key plugins using phpMyAdmin, so that I could try and get rid of unnecessary ones from old plugins.

    Took a long time though. Next time I think I might just do a wholesale export and delete the extra tables.

  7. Richard Hay (14 comments.) says:

    One of the things I did mot mention that a couple of you commented about is cleaning up the database. I did this during my iniital move to a new host. I got rid of things from old plug-ins in the options table as well as removing tables from those same plug-ins within the database.

    It helped a lot – trimmed the database down from 40MB to less than 20MB! Most of that was from stats plugin that really fill your database quickly.

    • dan (1 comments.) says:

      I use the “WP-Optimize” plugin to clean the database and remove post revisions, etc.
      I’m always amazed how much the post revisions (created whenever you preview a new or modified post or page) fill your database!

      Thanks, dan.

  8. Chris Bryant (12 comments.) says:

    This would have been great a couple of months ago :) I managed to move everything but lost my link roll :( (not a huge deal).
    One thing I did was to leave the old site up and dns pointed to it, but put in the IP of my new site in my /etc/hosts file (I’m sure you can do that on Windows as well- somehow), which made it easy to compare and tweak.

  9. naeem (3 comments.) says:

    Also planning on moving my website to a new host (mediatemple in my case)

    How would you handle plugin settings? specifically all-in-oneSEO, Nexgen etc – or is this all handled by the DB manager?

  10. Fred (1 comments.) says:

    Invaluable advice, thanks for taking the time to write this. Best regards,
    Fred

  11. Jitendra Kumar (2 comments.) says:

    Ultimate information..just loved it.

  12. Dustin (4 comments.) says:

    Great step-by-step guide Richard. Made sure to bookmark it since I will be transferring my blog to a new host pretty soon. Really need an affordable, reliable VPS that offers more granular control than my shared hosting.

  13. tom g (6 comments.) says:

    NIce info! PLanning to move some sites to my vps from other shared servers. I feel better about doing it now thanks! =)

  14. Andrew@BloggingGuide (63 comments.) says:

    This will really be a great resource. A very detailed one at that. Will be bookmarking this, just in case. Thanks for sharing your experience.

  15. Nicolas (25 comments.) says:

    This is certainly useful for people like me that have their dev installs on a different server before putting it out on the web. It’s also a thing I love with WordPress. You can show off things on your test site and then easy move it to the final destination on the web.

    Just a note to the Plugin. Although it doesn’t really matter for this one but Lester is no longer officially supporting his Plugins.

    • Texx Smith (6 comments.) says:

      yup, but if their production server is diff than your dev server . . . Like I recently had with a client with a pre-exisiting GoDaddy account. It can cause problems like mysterious errors that need tracking down and worked around. Sometime it’s best just to back everything up and work live, sometimes.

  16. bilder hochladen (1 comments.) says:

    ust backup the whole database and wp-content, and then restore.

    For changing the site URL, u must go to database’s wp_options and edit rows ’siteurl’ and ‘home’.

    Then u’re ready to move everywhere u want.

  17. Texx Smith (6 comments.) says:

    I recently updated an old version (2.1) of a WordPress Blog on a GoDaddy server. Man, I hate to diss on such a big company, but there tools for working with hosting and databases are all screwy, it’ll really slow you down. Trying to work with a database without PHPMyAdmin, is really time consuming.

    The point being, know what kind of tools they have AND how well they work before recommending a host for a client, unless you have your own server. What can do a bout someone who has all that purchased before they even contact you. It kinda stinks to have bill them extra because the server took 3.5 hours to back up a database that was less than 1MB in size. (No exaggeration), for example. what am I supposed to say after that? “I told you so?” Nope, gotta spin it as positively as I can . . .

  18. max (1 comments.) says:

    If you use SSH, Godaddy as hosting, and linux commands, moving wordpress site could be done snappier, that’s how I do it. It takes me less than 1 hour for moving to a new server since Godaddy DNS can point to the IP address of the server fairly quickly. But you will need a dedicated server with shell access.

  19. Eric (1 comments.) says:

    I went through a heck of a lot in my recent WordPress transplant.

    One thing to make sure of – check whether your new host has .htaccess files enabled, since WordPress uses them to set up the URL rewriting rules. If they’re not enabled, nothing but your root blog page will load.

    To check that, look in your apache.conf/httpd.conf file (if you have access, shared hosts might not). If it says AllowOverride All, you’re set, if it says AllowOverride None, your .htaccess files are going to be ignored. It is frequently set to ignore them because it’s more efficient to just include that stuff in the apache.conf/httpd.conf file, as it will be read once rather than on every request.

  20. maxds (1 comments.) says:

    If you have root access as with a dedicated hosting account, the whm panel has a one click migrate website feature that is just that easy. If you are on shared hosting, tech support will often do this for you for free when moving to a new provider

  21. bubazoo (213 comments.) says:

    I use web hosting providers that use CPanel. That way, the wordpress blog can be moved in a single mouse click, pretty much..
    makes all this nonsense in this blog post completely obsolite.

    the other thing I do periodically, is run an sqldump of my
    database into an ASCII .sql file. That way if something
    screws up, I always have a backup, in an ASCII text file format.

    I don’t trust FTP to transfer data, because CRC errors are getting more and more common. I just do an sqldump, since everything is in the database for the most part anyway, and just reinstall WP over again, no big deal. *shrugs*

    • Richard Hay (9 comments.) says:

      My host also uses cPanel which I like a lot. I do use FTP and trust it – never had an issue with it to this point.

      I guess when that bug bytes I will have to look at it then.

  22. Dan R Morris (1 comments.) says:

    I thought there was an “export” function in the dasboard, and subsequently an import function when you load up a new blog.

    Also, I didn’t understand flushing the DNS on your machine. What does that do?

    Dan

    • Richard Hay (9 comments.) says:

      Dan – there is an export and import function that only draws out the posts and comments. All the options data and any data stored by plugins in your database do not get exported in that function.

      That means you would have to reinstall all the plugins, themes, etc. and set them up again. I just find it easier to copy the entire directory structure, restore the database and it is up and running.

      As for flushing your DNS – when I am connected to COMCAST I use their DNS services and a local copy of some of the stuff I have accessed is kept on the local hard drive to speed up the browsing process. By flushing your DNS on the local machine you clear that cache and force a check of the DNS to your DNS server.

      I found that this worked for me to get at th enew site within about 10 minutes of inputting the DNS change at my domain registrar.

      Hope this helps.

      Rich

  23. Michael Brown (1 comments.) says:

    Richard
    Thanks for posting this, I have bookmarked it so that I’ll have a guide when I need one. I have 2 questions:
    I use the WP-DBManager plug-in and get the weekly updates via email, what is it backing up? The whole blog with posts etal or simply the stats and settings for widgets and plugins?

    The second question (Yes I’m a newbie)you say to ping the DNS from IPConfig that means from your “home” Computer to the server at whichever host on the net is in charge of the domain at the time of the ping. I have only used ipconfig for local area servers.
    Thanks, Mike

  24. Texx Smith (6 comments.) says:

    Right on Bubazo. Cpanel rocks! Sometimes a client has a client contacts you with a web site on a inferior Web Host and we have to be prepared to do what we gotta do to get them off of there.

  25. SEC (1 comments.) says:

    Flushing the DNS clears out the cache so that new pages arent loaded from cache

  26. Josh Boxer (1 comments.) says:

    Great Post Here. I actually had to move my wordpress blog from wordpress.com to wordpress.org and have it hosted, etc. I also had to move my hosting from Godaddy (Which lost 6 months of blog posts and charged me $200 to retrieve it!!!) to another hosting company.

    Fortunately I have a very good contact that knows wordpress and PHP like the back of her hand so she was able to take care of the migration for me. If your not savvy in this area, I would suggest sourcing it.

    Thank you for the very thorough information here.

  27. Scott (1 comments.) says:

    I actually did move my WP blog from one host to another recently. Rather than go through the learning process, and then not use it for so long that I will forget it anyway the next time, I hired someone to do it for me (thank you Craigslist).

    We did it by remote access so I could watch everything, and I was surprised to see that it really wasn’t that difficult. If I should ever need to do it again, I would probably do it myself.

  28. Jonathan (1 comments.) says:

    Great Instructions!

    I can’t stress how important it is to follow the steps in order and make sure that you get all of your database information correct in the wp-config area. I was stumped for about an hour until I realized that I had fat-fingered a value.

  29. Brian J Hoskins (1 comments.) says:

    I couldn’t get WP-DBManager working because there was a problem with my MYSQL dump path and my MYSQL path. I wasn’t sure how to sort that out, so I attempted your tutorial using the PHPmyadmin method.

    It took me HOURS. I could never get the website working. Eventually I managed to figure out that when I was importing my database, the imported tables had a truewp_ prefix whereas the original tables just had a wp_ prefix.
    So, I deleted all the wp_ tables and then renamed my truewp_ tables to wp_xxx.

    That left me with a working front page, but the rest of the site didn’t work and I could no longer log in.

    After a lot of messing about I sorted the login issues using this tutorial:

    http://beconfused.com/2007/how.....wordpress/

    Then I could at last log in, but only the front page of my site was working. Any attempt to visit a page or post resulted in a “page not found” error in the browser. I checked the permalink settings, and they seemed to be already correct, but after clicking ‘ok’ the rest of my site was working! So it seems it needed to update the permalink setting.
    Then after that I found my author box wasn’t working, but there was a slight difference between the username of the original post and my new username. So I just visited each of my posts and clicked ‘update’ so that the new author was the correct one.

    Done. My site now works. Phew!



Trackbacks/Pingbacks

  1. [...] Moving Your WordPress Site and Database [...]

  2. [...] Moving Your WordPress Site and Database [...]

  3. [...] Moving Your WordPress Site and Database « Weblog Tools Collection – here comes a time you may have to leave one web host for another. No matter the reason the idea of relocating an entire website – especially one that has been online for sometime – can seem very daunting. With a WordPress based site – I found it easi… [...]

  4. [...] Cleaning Up A WordPress Database After Plugins and Themes Are Uninstalled No responses by Richard Hay  on May 28th, 2010 in WordPress Discussions, WordPress Plugins I have been thinking about this post for a while.  It really started to come to me after I went through a server move of my own website which I discussed on this site last month – Moving Your WordPress Site and Database. [...]

Obviously Powered by WordPress. © 2003-2013

page counter
css.php