How To Copy Your WordPress Blog To Your Localhost

Overview:

This how to tutorial will explain how to copy your WordPress blog from your webserver to your home pc and run it on your localhost.  First we’ll talk about what I’m using because your situation might be different.  Then, we’ll talk about a couple things that you should already know how to do that are prerequisite.

The goal of this tutorial is to be hacker proof by knowing how to back your blog up to your home pc.  There are other conveniences of being able to ‘run’ your blog from your localhost too, like being able to tinker with it.  This is conceptually no different than backing up files at home to an external hard drive.   After you’ve done this a number of times, the whole process should only take you 10 to 15 minutes depending on the size of your blog.   Once you have this process under your belt, you can screw around with PHP and CSS to try different things out with no fear.  If you get hacked you won’t care either because you’ll be backed up.  This is a good procedure to add to your knowledge tool box.

Software Used:

I’m using Worpress on a GoDaddy server to run my internet blog.   I’m using FileZilla to transfer files to and from my home computer to the internet which is a free opensource SW application.  I’m using Notepad++ which is an opensource text editor.  I’m using XAMPP to run my localhost which is also free opensource SW that is bundled by the good folks at XAMPP.  My operating system is Windows 7.

Prerequisites:

I’m going to say that this process is easy, but I have a caveat:  you should at least have a minimum command of basic PHP to know what the following code does:

<?php
echo "Hello World";
?>

If you don’t understand that little block of code above, this tutorial is probably over your skill level.   You can still try this, but you should know at least that much and a couple more things:   You should know how to use phpmyadmin at a novus level.  You should know how to use Filezilla at a novus level.  And you should know how to install XAMPP and have it installed and up and running.  There are many YouTube tutorials on these subjects.  I’m new to all this too and can say that all of things are things you can learn watching youtube.

Optional Prerequisites:

I recommend the WP-DBManager plugin be installed by any WordPress user and it definitely helps in this process.  This plugin requires a WordPress.com API key which requires you to have a WordPress.com blog too.  It only takes a minute to set up a WordPress.com blog and once you have your API key, you might as well use it for these plugins too because they’re totally awesome:  Akismet and WordPress.com Stats.  Click on the picture below for more detail.

Let’s Get Started With The Process:

1)  This step is optional, but recommended.   Update your WordPress version and your plugins / themes / et al.  It’s a good idea to do any general housekeeping so the version you copy over to your home computer is at least the freshest most up to date version of everything.

2)  Do a copy of your database using the plugin described above.   I also recommend using the plugin to setup automatic backups.   You don’t need the plugin to make a copy of the database.  You can use phpmyadmin or any other method you want to make a copy of your db.  Remember where you saved the db backup because we’re going to import it later in this process.

3)  Now, you can fire up Filezilla.  We’re just going to copy the whole damn folder from the webserver to our local drive.  Check out the picture below to see a graphical depiction.   This is as simple as copy / paste the whole folder.  This step may take some patience depending on the size of your blog, the number of pictures & videos, and your internet connection speed.  This blog, with every post you see prior to this post took me about 10 minutes to get copied over.

As you can see in the picture below, I had already copied the whole folder over.  That is why you can see it on both sides of the screenshot.  Remember, this is your entire WordPress blog/installation.

4)  Now, you can goto your address bar and type in the location of your blog.  We’re going to display an error at this point because we have a couple more tweaks left to go.  But I just wanted to show you this step.  If you type your local URL in the address bar, you should see an error that looks like the one below.   I thought this step important because I remember thinking that this should be easy and then I hit this little roadblock and it took me a minute to figure it out.

5)  We’re almost there.  There are just a couple more things we have to do before we can launch our blog successfully on our localhost.  Now we need to open up phpmyadmin and create a db and import our backed up db into it.  Remember I said that we were going to need our db backup later?

Open up phpmyadmin and create a database by typing any name you wish as depicted below.  I used ‘yourdatabasename’ for the screenshot but my real database is ‘mawdizzdb’ which you can already see on the left hand side because I have already completed all the steps.

Now, while we’re still in phpmyadmin, click on Import in the upper middle menu bar.

After clicking on import, you will see the “Choose File” button as you can see in the picture below.  Go ahead and click on it.  The Upload File dialog box will come up.  Goto where you put your backup db.  I tried to scootch that dialogue off the screen a little so you could see everything.    So to recap:  click on Choose File and choose your .sql backup file to import.

Congratulations!  you just imported your WordPress db to your local machine.  If you click on it, you should see all the WordPress tables as shown in the screen below.

6)  Okay, now it’s time to tweak a couple data fields in the wp-options table and we’re really close to done.  Click on the wp-options table and look for option_id #2.  This will have the internet URL for your blog.   You’re going to want to change it to your local path as depicted in the screen shot below.  All you have to do is click on the pencil icon and change the value.

UPDATE 01/08/2011:  In case the option_id# is no longer #2, the option name is ‘siteurl’ regardless of its number.

We also need to do the same thing for option_id #39 which is on the next page over.  Get there by clicking the > icon.   See the picture below.

UPDATE 01/08/2011:  In case the option_id# is no longer #39, the option name is ‘home’ regardless of its number.

7)  This is the final step.  I have a couple more notes after this for a couple things, but this is the final step.  In the folder you copied over from internet to your local machine, there’s a file named wp-config.php.  This file has all the constants for your database connection.  You now need to tell this file the following information so WordPress will know how to connect to your database:  Your username, Your password, Your db name, and Your host name.

Below is a screen shot of how this file should look using the default XAMPP information.  The default XAMPP info is ‘root’ for username, ” for password (which is two apostrophes side by side indicating there is no password), and ‘localhost’ for the host name.  The db name was specified by you when you created the db name in step#5.   Reference the picture below to see what this looks like.

That’s it.  We can now go type the path to our blog in the address bar and our blog will launch.  Check out the picture below to see what I mean:

Remember before using the exact same path we had a database connection error?  Well, we obviously resolved that error.  We’re now up and running on our localhost.  I have a couple more useful tips for you:

  • Your username and password to login to your local blog dashboard are the same as the ones you use when you’re on the internet.
  • I recommend deactivating any plugins that are unnecessary on your local blog.  For instance, a stats plugin or a database admin plugin are no longer necessary.  But, a beautification plugin like fancybox or something is still applicable and you can still leave it running.
  • I further recommend deleting the plugin files for plugins you’re not using if you are experiencing weird stuff when you’re viewing your dashboard via your local blog.  These files are located at: yourblogfolder/wp-content/plugins.
  • You may notice output/buffer errors in your dashboard for plugins that are still active.  For example fancybox.  These are non-fatal errors.
  • If you have problems getting to your posts on your localhost, it could be because of your permalink structure.  If you have a custom permalink structure like ‘/%category%/%postname%/’ in order to help your SEO, just change your permalink structure to the default.  This should remedy any unexpected errors you’re having on you localhost if you click on a post or a category and you don’t get what you expected.

Conclusion:

This process shouldn’t take you that long once you’ve done it a couple times.  You can now know that your blog is safe and secure on your home computer.  This will give you the peace of mind that if you ever get hacked, you have a copy of your blog that you could put right back up and you wouldn’t lose a thing.  Also, you can now tinker and practice your PHP and CSS skills.  You can try all sorts of things without worry of screwing anything up.

This process would be exactly the same if you wanted to move your blog from one host to another on the internet.

One of the things I’m learning about websites is that they’re not really “programs” in the traditional sense.  When someone says “install” WordPress, that’s really a misnomer.  It’s just copying a collection of files from one place to another.  These files aren’t really “installed” like they are in Windows when the registry is updated, they’re just “copied”.

Now that I know this, I would much rather deal with the files myself.  I know how to copy a file.  So why use utilities and such when you can just copy the files.  Learn this and FEAR NO HACKER.  Back your shit up and forget about it.

There’s more than one way to skin a cat and there are more ways than one to get your blog on your localhost.  If you’re having trouble with this method, there are some others you can try; especially if you’re afraid or uncomfortable working with the database or phpmyadmin.  You can go to the tools section of your dashboard and click on export.  From there you can spit out an XML file.  There are some cool settings and parameters you can use to get just what you want.  You could do a fresh install on your localhost and then import that XML file too.  Some people find that way easier.

I like this way because it’s so easy and fast.  Like I said, once you’ve done it a couple times, it doesn’t take that long at all.  The longest part of it all is copying over the files.

 

11 Replies to “How To Copy Your WordPress Blog To Your Localhost”

  1. After a few miss-steps I finally have a copy of my blog on my localhost thanks for the info.

    Question:- As your blog expands and you want to keep localhost up to date. What is the best way. Delete the DB from phpmyadmin and create a new DB each time,or is there a simpler way.
    Bob

  2. I think the easiest way is to goto the Tools section of your dashboard and export an XML file and only specify the date range of the posts you want to add. This can be a neat way to do an update or sync your localhost to your internet blog very fast. It is very easy to follow the prompts and export only the stuff you want from the internet. Just be careful to only export the specific things you want to export. Then you can go over to your localhost blog and import that XML file. This is the easiest and fastest way to sync the blog back up after you have completed the process above. I think the process above is faster if you’re starting from scratch.

  3. Matt,
    Thanks for the updates.
    Last week I did a site backup, then downloaded the complete WP-content folder to my localhost, overwriting old files. Then went to PHPmyadmin, deleted old site DB, then created new DB imported the new DB from the backup folder in the WP-content,changed SiteURL and home to localhost. Opend site in localhost and signed in without having to edit wp-config.php.
    I am using Wamp as localhost.
    I will do another backup soon to see if I need to re edit the wp-config.php again or was it a fluk last time.
    Thanks again for your help.

  4. Good thinking. I like that idea of just grabbing the wp-content folder. In fact, you could even rifle shot off the folders inside of that folder if they’re pretty big. For instance, in the upload folder inside of the wp-content folder, WordPress creates a folder for each year and month you upload media. If you’re uploading a ton of photos or videos or whatever, you could just grab the folders created since your last update. You might be splitting hairs a little, but depending on the size of those folders for you, it could be worthwhile.

    I’m up to four wordpress sites now on the internet and I’m tinkering with copies of all of them on my localhost. I’m going to try what you did in order to speed up the “sync” process for future syncs. I hope you’re finding it easier after having done it a couple times. I feel like it’s a piece of cake now. Updating the database through phpmyadmin is super fast/easy once you have the hang of it. I really like the WP-DBManger plugin by Lester ‘GaMerz’ Chan because it’s easy to configure and will email you a ‘.sql’ file of your db at whatever interval you specify. It makes it so your fallback is never more than one week should something go wrong and you don’t have to do any extra steps. You need a wordpress.com blog account in order to get an API key to use the plugin, but I think it’s worth it. It only takes 5 minutes to set up a wordpress.com account and then you can use WP-DBManager and Akismet too.

    The ‘wp-config.php’ file is in your main folder, so you’re not overwriting it when you only copy the wp-content folder. That means what you did was not a fluke. Even if you overwrote the ‘wp-config.php’ file, you could always modify it again which is not that big of a deal.

    Nice job and thanks for the additional ideas.

  5. Just found a problem. I downloaded my latest backup and when I tried to create and import the data base it has a file size limit of 2048kb and would not create the data base. My backup is greater than 2048 kb.
    Any suggestions. Bob

  6. After a break I figured out what to do. Apparently you have to edit the php.ini file to increase the file from 2kb to whatever size you want.Open phpadmin and click on PHP. Click on php.ini and it should open in notepad (WIN)scroll down to the file upload section and change
    ;;;;;;;;;;;;;;;;
    ; File Uploads ;
    ;;;;;;;;;;;;;;;;

    ; Whether to allow HTTP file uploads.
    file_uploads = On

    ; Temporary directory for HTTP uploaded files (will use system default if not
    ; specified).
    ;upload_tmp_dir =

    ; Maximum allowed size for uploaded files.
    upload_max_filesize = ??M <— change here ….

    I just did this and it works.

  7. Bob, my email must be slow… I got your email and figured out the exact same thing you did and was just going to answer you when I saw that you had already figured it out. I’m glad it worked and I will note that for future reference.

  8. This is absolute genius, esp the reminder regarding the permalinks. I have spent days trying not just to get this to work, but to find a reference to it that made sense to me. I am not a programmer but I do create and manage hosted WP sites.
    I had used Tools/Export online to get a file that I imported in through Tools on the localhost site (I installed WAMP). It did not include the plugins, child theme, images, and menu structure. I then pulled in the entire wp-content folder, and the images folder. Still not complete. I downloaded the database and imported it, which resulted in my needing the fix you just supplied. I think that did it.
    It is less clear to me how I FTP up changes and additions to my pages etc. Would not the permalink go with it? When I used Dreamweaver for a regular website, the upload was a piece of cake.
    Thanks again.

  9. Terry, thanks for the compliment. I’m starting a site called wandelogic.com where I’m going to be putting WordPress tutorials on security and basic management. I hope it’s up your alley and you can benefit from it. Regarding changes to your pages, there is a file called page.php in your theme folder (most likely) that WordPress uses for displaying a page. The basic html for the page comes from the WordPress admin panel, but the header, footer, and structured html for the page comes from the page.php file. I’m doing a tutorial on theme building in my wandelogic.com site which I think will make all this clear to you. Please check back there if you’re interested. Here’s a link that gives you the entire WordPress hierarchy for what page is displayed: WordPress Template Hierarchy

Leave a Reply

Your email address will not be published. Required fields are marked *

*