Moving Wordpress from hosting to Localhost

Moving WordPress from hosting to localhost can be done in several ways. But in this time I will try to explain two of them.

The first way (the easiest one) is by using Wordpress Export/Import Tools.

But before we begin to move the WordPress from hosting to localhost make sure that you have already installed a fresh copy of Wordpress on Localhost. You can follow the instruction here on How to Install WordPress on Localhost.

Login to your live WordPress Blog, enter the Admin page. In the navigation menu, mouse over the "Tools" menu and then click "Export"

Download Wordpress XML File

Check "All content" to download all your posts, pages, comments, custom fields, categories and tags in a single WXR (xml) format.

Click on "Download Export File" and save it in your computer.

In Localhost, login to your WordPress, enter the Admin page from the Tools menu click "Import" and then klick "Wordpress"

Wordpress Importer

By default Wp importer plugin is not installed with Wordpress, so if you see a pop up window about the plugin, just klick "Install Now" to install it.

After the plugin has been installed you'll be taken back to the Wordpress import window, browse to the WXR (xml) file you've downloaded and then klick "Upload file and import"

Import Wordpress XML File

Make sure you are connected to the internet to be able to download file attachments. Create a new user or select a user for "assign posts to an existing user", check the "Download and import file attachments" checkbox and then click "Submit"

Worpress Attachments

Open your FTP program and download plugins/themes from your hosting. Switch the theme and activate the plugins, arrange the widgets to make it look exactly like your live Wordpress.

Done.

The second way is using phpMyAdmin to Export/Import database.

This method is a little bit complex but more efficient because all the settings, themes, plugins, widgets and even username and password will be exact the same as live Wordpress.

I want to tell you that this method also can be used to move Wordress from one hosting to another hosting as I did or to move Wordpress to a new domain as well.

Here is a step-by-step guide to move Wordpress from hosting to Localhost

Open your favourite FTP program and connect to your hosting, navigate to the path where the WordPress is installed.

Download "wp-content" folder and its contents, or you can use cPanel File Manager to compress the "wp-content" folder, so the file will be much smaller to download.

Replace "wp-content" in localhost (D:\My Websites\wp-content) with the new downloaded "wp-content" folder.

Login to Cpanel and then click phpMyAdmin.

cPanel phpMyAdmin

In the database list, click your WordPress database (if you are unsure, open wp-config.php to find out what your WordPress database name is). In this example mine is "htmlcss"

Select Wordpress Database

Click "Export" to export the database

Export Wordpress Database

In the Export Method select "Custom - display all possible options"

Export Wordpress DB Option

Select "zipped" or "gzipped" for compression type.

Export Wordpress DB Compression

Click "Go" to start downloading the database.

Open phpMyAdmin on localhost, if you followed the instruction here on how to install phpMyAdmin on Windows, you could open it by typing "http://localhost/phpmyadmin" in the browser address bar.

If you want to use WordPress database that you have already installed, select it and at the bottom of the table list click "Check All" then select "Drop" in the drop-down list and click "Yes" to delete all the tables.

Drop Wordpress DB Tables

Or if you want to use a new database, here is a guide of how to create a new database and then edit wp-config.php to match the database name.

Select the database that you want to use and then click "Import" browse to the zip or gzip that we have downloaded earlier.

Import Wordpress Database

Click "Go" to start importing the tables into the database. If everything went well you should see something like the image below.

Success Wordpress DB Import

In the Wordpress table list click "wp-option"

Wordpress Options

In the table rows list find "siteurl" option_name and then click "Edit"

Worpress Siteurl

Change the option_value with "http://localhost" click "Go" to update wp_option.

Wordpress Siteurl Value

Still in the table rows list find "home" option_name and then click "Edit"

Wordpress Home

Change the option_value with "http://localhost" click "Go" to update wp_option.

Wordpress Home Value

Now try browsing to "http:/localhost" to view your blog then login using your username and password live Wordpress.

To be safe and to make it load faster, you should remove any scripts from your theme and widgets that require internet connection such as Analytic, Webstats, Shoutbox, Adsense Script etc...

If you face the problem with "the requested URL was not found on this server" try to resave the permalink settings in the Wordpress settings page.

Tips:

If you still got problems, something like some links or images that still point to your live WordPress, here are other options you might try:

1. Global find and replace.

Unzip the database you've downloaded and open it with text editor (Notepad++ or Dreamweaver) and use "Find and Replace" option to change "http://yourdomain.tld" with "http://localhost" and then import it with phpmyadmin.

2. PhpMyadmin's SQL queries.

Open PhpMyadmin (http://localhost/phpmyadmin) select WordPress database, on the top menu click on "SQL"
In the lines below change "http://yourdomain.tld" with your own domain, copy and paste them into the phpMyadmin's SQL queries and then hit "Go"

UPDATE wp_options SET option_value = replace(option_value, 'http://yourdomain.tld', 'http://localhost');
UPDATE wp_posts SET post_content = replace(post_content, 'http://yourdomain.tld', 'http://localhost');
UPDATE wp_posts SET guid = replace(guid, 'http://yourdomain.tld','http://localhost');
UPDATE wp_links SET link_url = replace(link_url, 'http://yourdomain.tld', 'http://localhost');

18 comments:

  1. This is what I am looking for. I am still a wordpress newbie and I love what I learned from here. Thanks!

    ReplyDelete
    Replies
    1. I second the above comment. You have no idea how much this helped in my work. Thank you so much! (:

      Delete
  2. This seems to be an awfully simplified approach, especially since it doesn't address the serialized database aspect. Almost all other approaches require that you use some search and replace tool such as the one from interconnectit to do the global search and replace.

    ReplyDelete
  3. Thanks for the tutorial... but is there a way to automatically update the live site from a localhost? I mean like in dreamweaver where you have the options to connect to the ftp?? So you don't have to import/export everytime you have changes to be made...

    pls like and follow my blog @ http://random-stuff-online.blogspot.com

    ReplyDelete
    Replies
    1. No, you still need to import/export your database (posts, comments, and settings) to be able to update your Wordpress site.

      When we setup Dreamweaver FTP correctly, it can be used to upload/download, update and synchronise Wordpess files/folders between local and remote server.

      Nice blog by the way :)

      Delete
  4. OMG...I've been searching ALL day for this.

    The biggest thing I learned was the re-save permalink settings. That was awesome!

    ReplyDelete
  5. I have done everything that you have said in this post (as well as looking at other tutorials) and I am getting the error:
    Error 404 - Page not found!
    The page you trying to reach does not exist, or has been moved. Please use the menus or the search box to find what you are looking for.

    Is there something I am mising?
    Please help! I have looked everywhere! I am trying to get my site from a live domain to a local host.

    ReplyDelete
    Replies
    1. Is that a WP error 404 page? if so, maybe mod_rewrite is not enabled in your httpd.conf, you can read it here for more detail. After that, (if exists) delete .htaccess from your Document Root and go to your WP Permalink Settings, try to change your Permalink structure and then save.

      Delete
    2. Thank you for replying!
      Yes I am using wordpress - so I am basically trying to move a wordpress site from a live domain to a localhost.
      It seems like it is much more tricky than the other way round!

      The landing page gives me a wordpress 404 error.
      When I try going to wp-admin I get:
      Not Found

      The requested URL /wp-login.php was not found on this server.

      I understand if this is not to forum to get assistance but I just can't figure out why I cannot get it to work after trying numerous tutorials!

      Delete
    3. I think it's good just to start over, maybe you've entered wrong url into the wp-option.

      Delete all the tables and reinstal WP and try posting some posts and play with the permalink structures and see if it makes the same problem.

      Go to WP setting and write down the WordPress Address (URL) and Site Address (URL)

      After you've imported the live WP database, enter the WordPress Address (URL) into "siteurl" and Site Address (URL) into "home"

      If the the problem still persists, check if you use any WP rewrite plugin, or simply rename wp plugin folder to something else.

      Delete
    4. Sorry for the delayed response (a bit like my brain at the moment).
      I have finally worked it out!
      It was my foolishness as I hadn't put the live site directly into the root so it needed an extra location (/).
      My issue now is that when I try to log on to the Wp-admin it doesn't accept my password. I have checked that it is correct with the live site.
      Is there a way to reset passwords? Or is there something else I am doing wrong?

      Delete
    5. You should be able to login using live WP Password. I guess, there must be something wrong but you can try to reset password and see if that works.

      There are many ways to reset Wp Password, resetting through phpMyAdmin is the easiest one.

      Delete
  6. Thanks for the tutorial sir. I used the second option and all is running well BUT I'm having issues with images.

    How do I change the URL of the post images to link to the copies on localhost and not those online?

    Thanks sir.

    ReplyDelete
    Replies
    1. Here are other options if the above option does not work for you. it can happen when we manually insert images to the posts or using absolute links for internal linking.

      So, the best way is do global find and replace.
      Unzip the database you've downloaded and open it with text editor (Notepad++ or Dreamweaver) and use "Find and Replace" option to change "http://yourdomain.tld" with "http://localhost" and then import it with phpmyadmin.

      Or you can also using phpMyadmin's SQL queries. Change the "http://yourdomain.tld" below with your url, copy and paste them into phpMyadmin's SQL queries and hit "Go".

      UPDATE wp_options SET option_value = replace(option_value, 'http://yourdomain.tld', 'http://localhost');
      UPDATE wp_posts SET post_content = replace(post_content, 'http://yourdomain.tld', 'http://localhost');
      UPDATE wp_posts SET guid = replace(guid, 'http://yourdomain.tld','http://localhost');
      UPDATE wp_links SET link_url = replace(link_url, 'http://yourdomain.tld', 'http://localhost');
      UPDATE wp_links SET link_image = replace(link_image, 'http://yourdomain.tld', 'http://localhost');
      UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://yourdomain.tld', 'http://localhost');
      UPDATE wp_usermeta SET meta_value = replace(meta_value, 'http://yourdomain.tld', 'http://localhost');

      Delete
    2. Thanks a lot sir. The SQL queries helped fix the problem ;)

      Delete
    3. You're welcome, I'm glad the SQL queries fixed your problem. :-)

      Delete
  7. Thanks so much for this tutorial! It helped me a lot!

    ReplyDelete
  8. Great blog article about this topic, I have been lately in your blog once or twice now. I just wanted to say hi and show my thanks for the information provided. T&T Web Services

    ReplyDelete