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.
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.
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.
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.
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.