How to create a local copy of a wordpress site

This article explains how you set up a copy of a WordPress site on your computer. This can be very useful if you need to find out what will happen if you do an upgrade, for testing out and playing with plug ins, and for developing WordPress themes.

This article is aimed at PC owners. I use both PC and Mac, and this time I had to do this task on my PC. The principles can also be applied to a Mac, and I have already written a group of articles for Mac which will be linked to from this article that achieve the same results.

We’ll be going through the following steps:

Here we go…

Installing PHP, MySQL and Apache

Mac users

Go to my tutorial on setting up PHP, MySQL and Apache on a Mac.

PC users

There are many packages available that allow a one click installation of PHP, MySQL and Apache on a PC. I looked at a few and settled for WAMP, as its kept up to date, is relatively lightweight and easy to use.

  1. Start by downloading WAMP.
  2. Run through the installation, accepting the defaults.
  3. You should now see a new icon in your taskbar – that’s WAMP! If you don’t see it, just start the software by clicking on the icon, or locating it in your programs.
  4. Start your webserver by left clicking on the icon in the taskbar, and selecting Start All Services. Nothing will happen – the services run behind the scenes.
  5. Open a browser and go to http://localhost/, if you see the WampServer homepage then you’re ready to start setting up wordpress.

Copying the WordPress install over from your remote host

Next you are going to download WordPress from your remote host and set it up as a local site.

  1. Using your preferred FTP client (I use the excellent free filezilla) download all the files in and including the folder associated with your WordPress install. If your WordPress is in a folder called ‘wordpress’, you need to download the whole folder.
  2. Place the downloaded folder into the WAMP folder www. This is where all files to be run on the webserver need to be placed. This can be found by clicking the WAMP icon and selecting the ‘www’ directory option. Its also in C:/wamp/www
  3. Once the downloads are complete, go to http://localhost/the_name_of_your_wordpress_folder, you should see a database error. If you do, its all worked! If you see a server error, its likely to be your .htaccess file – try removing it temporarily.

Copying the database

Now you need to get all the tables associated with WordPress out of the remote server, and onto the local server. You’ll probably need to use PHP MyAdmin, which most hosts include by default. If this isn’t available and your using a version of WordPress which is later than 2.0.3 you can try the wordpress db backup plugin.

  1. Log in to PhpMyAdmin
  2. Select the database containing your WordPress tables, note down its name
  3. Select the Export Option
  4. Select all the tables related to this WordPress installation
  5. Ensure you download as SQL, check the Data box, so all data is downloaded – complete and extended inserts. Check the box so you save as file and select no compression (it sometimes goes wrong).

Next you need to import this data into phpMyAdmin on your local WAMP server.

  1. Start PhpMyAdmin by clicking on the WAMP icon and selecting the option phpMyAdmin
  2. On the homepage there is an option called ‘Create New Database’, enter the name of the database from your remote server and click create.
  3. Click on your newly created database in the left hand column.
  4. Click import and browse to your downloaded file
  5. Click ‘go’ and all the data should be imported
  6. If you have problems with the size of your datafile, there are other methods – send me a mail, or add a comment and I’ll go into them. At the moment I’m trying to keep this document as simple as I can.

Next you need to set up the same username and password on this local database as is used on your remote database. You will have used these to log in to phpMyAdmin on your remote server, they are also in your wp_config file.

  1. Go to the homepage of the local phpMyAdmin and select ‘Privileges’
  2. Click the add a new user option
  3. Under username enter the username from the remote host, under host select localhost, under password and re-type enter the password from the remote host. Under privileges check all. Click go.

A note on user permissions – I had some issues with the host type – basically, in the wp-config file you need to check the DB_HOST entry. If the host is ‘localhost’ the user in the local mySQL should be set to host – localhost. If the host is ‘127.0.0.1’ the user should be set to host – any.

Finally, you need to change a couple of fields inside the wordpress database to ensure the correct web address is used.

  1. Go to the local phpMyAdmin
  2. Select the database containing wordpress
  3. Select the table wp_options
  4. Select browse
  5. Locate the option ‘siteurl’ and edit it so the option_value becomes http://localhost/local_folder_name
  6. Locate the option ‘home’ and edit it so the option_value becomes http://localhost/local_folder_name (this might be on the second page of database fields).

And you should now be done check http://localhost/local_folder_name.

Whats Next

Keep an eye out for many more WordPress tutorials over the coming weeks. I’m currently freelancing and am working on a bunch of WordPress sites for various people, as well as working on some open source themes, premium themes and plug-ins. Email me if you need any assistance – kirby [dot] mark [at] gmail [dot] com.

  • Thanks so much for this post, Mark. I didn’t know about the last part with the changes for the siteurl and home, and these are so important.

  • Nice one man, think I might give this a try. Nice work!

  • chris

    so frustrated…i’ve changed my ‘siteurl’ and ‘home’; however, when i navigate to my site on localhost i get a 404 not found error…

    the odd thing is it points to the .com address of the live site, but the folder name on localhost…obviously, i’ve done something wrong…but i can’t fathom what…

    any ideas?

  • Just wanted to say thank you for a superb summary of this process. I am just about to update our site (built on wordpress but not touched for a couple of years and long overdue an overhaul) and wanted to set up a local environment. Very useful article and much appreciated!

  • Pingback: Migrating a hosted WordPress site to your local PC :: ITauthor()

  • John

    A note on user permissions – I had some issues with the host type – basically, in the wp-config file you need to check the DB_HOST entry. If the host is ‘localhost’ the user in the local mySQL should be set to host – localhost. If the host is ‘127.0.0.1? the user should be set to host – any.

    Sir, could you explain what the above text means?

  • Demers Designs

    Great write up. I would like to add one more step that may or may not be necessary. If you are using a custom permalink structure, your links to individual posts and categories may not work when you bring your site to a local server. I have found that if you switch the permalinks back to default, save, and then go back to your custom settings, it should work fine. I assume it is something about the .htaccess file not copying from the live server. Hope this helps someone…

  • Thanks for the complete and easy to follow guide, now I have a working localhost and time to modify my templates. Thanks for this great guide! Keep it up 🙂

  • eggplant64

    Amazing! I’ve been having such a headache with this and then came across this page. Completely resolved all the issues I was having. Thanks you!

  • Kudos to you, Mark! This is the best explanation (and I took a good look at several) and the only trouble I had was just discovering (thanks to the Demers Designs comment) that I needed to set the permalinks to the default.

    Brilliant! Now I can demo a blog for an organization that won’t have an internet connection for our meeting.

  • Marcela

    Thank you so much for your tutorial. I was able to set up everything with no problems. I still have some glitches to solve but at least I now have a local copy of my site to play around with.
    This was great help

  • Pingback: Paul Kiddie’s Blog : HTTP Server error 500 Wordpress()

  • thank you for this. very clear and easy to follow.

  • Thanks Mark!

    Been looking everywhere and this is the first place mentioning the changes for the siteurl and home. And that did it!

  • Some people would prefer not update the database content every time they copy the database from Live back to their local system for development.

    The WordPress Developer Site has some documentation on patching the wp-includes/functions.php file to avoid any SQL changes when reloading the database.

    Running a Development Copy of WordPress at codex.developer.com.


    Ryan Erwin
    Shanghai, China

  • milesj

    Seemed so simple, however, when I followed all the steps and went to URL localhost:8888/wordpress (I’m running MAMP), the browser window is just blank. Similarly if I go to wp-login.php and login the screen browser remains blank.

  • sara

    Excellent write-up. I have problems when trying to import my database as the file is too big. How can I get around this issue?

    Many thanks

  • Beri

    Great guideline, many thanks!!

    I did have a problem though. The homepage was showing correctly on localhost, but clicking on any post or page resulted in an ‘cannot find url’ error. I finally found out how to resolve it:
    Go to http://localhost/portal/wp-admin/options-permalink.php and change the setting to default.

  • Takis Vakatasis

    hello Mark
    thank you so much for this detailed step by step guide…..i follow your steps and finally i made my wordpress theme working locally (my site is: http://www.judo.com.gr)
    Best Regards
    Takis

  • darkhoro

    OHH MAANNN thanks a lot, you helped me a lot !

    P.S : for people who use easyphp, put http://127.0.0.1:8888/folder_name in siteurl and home.

  • Damian Saunders

    Hi Mark,
    Thanks so much, I’d been frustrated with this for a while now and other tutorials don’t cover the php Admin steps like you did.

    Still have a couple of glitches with images using fully qualified URLs etc but there’s enough to develop and test.

    Cheers
    Damian
    http://www.damiansaunders.net

  • Ramon

    Hi! I have followed all the steps and the main page loads at http://localhost.
    However, when I click on any post or page, all I get are “Not found” errors.

    I have the Permalinks plugin by John Bloch installed and this is what is causing the problem. I changed the Permalink settings to default and now I can browse.

    However, this is not satisfactory since I do need to use the Permalinks once I’m done working on http://localhost and implement the changes to the live site.

    Can you or anyone here point me to the right direction on how to make permalinks work on http://localhost?

  • Fabrice

    Thank you so much for this tutorial. Great great stuff!

  • Winwood

    Helped me get my localhost copy up and running after a f]very frustrating few hours. Thanks 🙂

  • Etienne Sky

    Thanks Mark, this is straight forward and it succeeded in bringing my wordpress site up locally, at least the content.
    Unfortunately I don’t get the theme to load correctly. I do have a copy in the wordpress/wb_content/themes folder but it does not seem to get picked up. Would you know where the theme is selected and what I might be missing ?
    thanks

  • Matt

    This saved me a lot of trouble. Thanks very much!

  • Ratul

    Hi Mark,
    it works great. But I still have problems updating wordpress version offline, it shows the error:
    Downloading update from http://wordpress.org/wordpress-3.4.1-no-content.zip…

    Download failed.: Could not open handle for fopen() to http://wordpress.org/wordpress-3.4.1-no-content.zip

    Installation Failed

    Do you have any solution how to only download the updated file to an earlier version thats running in localhost?

  • David

    I cannot begin to tell you how helpful this walk through has been. Thank you *so* much for doing this.

  • Jose

    Developing in a test environment is alyaws the best way. You should never run untested code in production. I actually run a QA site as well on a shared host service so I can test deployments and ensure that it all works on a shared host. WP adds some extra twists when you deploy, like having to change all the URL’s in the database. MAMP is unnecessary. It looks easy at first, but installs thing in odd ways. The Mac comes with PHP and Apache already installed, all you need to do is install MySQL and you are ready to go. If all you ever use is PHP, MAMP may be good enough, just don’t try to install Python on it. I tried, after 4 hours of unproductive messing around in Unix mode I gave up, uninstalled MAMP and went with the standard Mac services.

  • jared

    fyi if your db is too large then you can create an .htaccess file in the /phpmyadmin directory to override settings:

    1.in /phpmyadmin directory, create an .htaccess file.
    2. type the following in the newly-created .htaccess file:

    php_value post_max_size 21M
    php_value upload_max_filesize 20M

    and then change the 21M/20M to whatever you need. make sure the post_max_size is as big or bigger than the upload_max_filesize.

    thanks for the tutorial!

  • Veeps

    I’m having a problem that I think is password related, though I could be wrong. I got as far as seeing an “Error establishing database connection” message. If the password is encrypted (in the wp_config file), say as “xyz123*”, but I know that password is “passwordx” – which do I use in phpMyAdmin under privileges? Encrypted or actual password? Thanks in advance.

  • darren

    Hi Mark,
    I followed the steps in the first part but it seems there are problems with the size of the imported database. I am receiving this error:
    “No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration.”
    What would you suggest? Help would be greatly appreciated!

  • Walter

    Please help.
    Under the table wp_options. I cannot find the “home”. Please show me where else can I look for.
    Thanks

  • Go to page 2, You’ll find it there 🙂

  • Lee

    Hi – I did all this, but for some reasons, when I try to access my site, I get a pop up that says ”

    <?php
    /**
    * Front to the WordPress application. This file doesn't do anything, but loads
    * wp-blog-header.php which does and tells WordPress to load the theme.
    *
    * @package WordPress
    */

    /**
    * Tells WordPress to load the WordPress theme and output it.
    *
    * @var bool
    */
    define('WP_USE_THEMES', true);

    /** Loads the WordPress Environment and Template */
    require('./wp-blog-header.php');
    "

    Any idea why?

  • Lee

    ooops – here it is

  • Julian

    I found the info below at this link and it solved this problem for me. – http://forum.wampserver.com/read.php?2,36154,36155

    Try these different settings in C:wampbinapacheapache2.2.8binphp.ini

    Find:
    post_max_size = 8M
    upload_max_filesize = 2M
    max_execution_time = 30
    max_input_time = 60
    memory_limit = 8M

    Change to:
    post_max_size = 750M
    upload_max_filesize = 750M
    max_execution_time = 5000
    max_input_time = 5000
    memory_limit = 1000M

    Then restart wamp to take effect

    Have fun,

  • Josh H

    Hi Veeps did you ever get past that error?
    I have the same error. Ive searched high and low and I cant get past it.

  • andonisr

    Hey there…when you say “The Mac comes with PHP and Apache already installed”, you mean….?? Where is it installed…how do you access it ? I went through hell to try and configure MAMP on my mac, and after countless hours of experimentation with local install of wp I finally got it working. Now I’m used to it and can play around with it, (mostly using phpmyadmin sections of it..! However, it would be good if you can tell me where is installed and does that mean I now have it installed twice…?
    Thank you..

  • Stephen

    Hi, I just wanted to thank you for this excellent tutorial on how to install a development copy of a production WordPress site. The only problem I had was with displaying subordinate pages, but once I changed the permalink option to “default” that worked fine. Also the SEO plugin did not like being moved to the local site.

  • Marcus

    Thanks very much, that worked a treat. Very clear

  • Katsdelight

    Great tutorial , really appreciate this. If you could help me I am getting an Error: 1004 sql query when importing the database file already exists. Thank you in advance.

  • Trevor

    I see a couple people having issues with certain steps. I found this tutorial that walked me through from start to finish and might help some of you. I am a total noob so it’s definitely pretty good. Here is the video:

    Part 1:
    https://www.youtube.com/watch?v=xn-8OvwFdBY

    Part 2:
    https://www.youtube.com/watch?v=fIIJBdpRzjM

    Hope this helps!