How to Run Your WordPress.org Blog Locally for Experimentation and Fun

If you have a WordPress.org blog and want to try a new plugin or a new look, you have two options: You could just install it on your running production site and risk crashing it. Or you could first experiment with it on a different test installation. Ideally this test system would resemble the real site as closely as possible. I think you can guess which one is the right way and which is the one most people go for. This article show how to copy your existing blog to a local computer and run it there, so you don’t have to fear trying out something new.

This tutorial requires some technical knowledge. How to set up a LAMP/WAMP stack, FTP files and use phpmyadmin. Nothing very complicated, but if you don’t feel comfortable doing it, I’d gladly help you out and create a fully working VirtualBox image of your blog for $50 (I’ll also support you in setting up VirtualBox).

(why buy from Streamhead?)

Step 0. Prerequisites

This tutorial won’t work for WordPress.com hosted blogs, only for self-hosted WordPress.org blogs. You will need to have an FTP account that can access your WordPress installation files. Every host offers this, so check your hosting details and keep the FTP url, login and password ready.

You will also need to export your database. The easiest way is via phpMyAdmin. I haven’t seen a host that doesn’t offer this super-useful application. A link to it is usually located in the control panel of your hosting account.

Step 1. Operating environment

Depending on your preferences, there are a wide range of operating systems and environments you can work with.

  • If you’re used to Windows and you like to keep it simple. You can install everything on Windows.
  • If you want to create something portable, I suggest running some kind of virtualization software. I’m a fan of VirtualBox.

Basically, pretty much any operating system will do, but I like to create a virtual Ubuntu system in VirtualBox. It’s a great way to keep the server software that you’ll install in step 2 away from your “normal” operating environment. Shut down the virtual machine and you don’t need to worry about system processes that keep using memory and CPU that you forgot to shut down.

Step 2. LAMP

While there are other ways to run WordPress, the easiest way is to install the Apache web server, MySQL database and PHP language. It’s the same environment that your blog host uses, so this is the best way to reproduce identical conditions.

Step 3. Copy WWW directory

Now it’s time to do the actual work. First you need to copy all the blog files locally:

  • Figure out where the local Apache server stores its files. On Ubuntu this will be in /var/www. Many WAMP distributions offer shortcuts to this directory.
  • Next open an FTP client. I like FileZilla, but feel free to pick the one you like.
  • Connect to your blog’s FTP site and navigate to the WWW directory. Usually it’s called “www”, sometimes “public_html” or something similar. There should be 3 directories in there that start with wp (wp-admin, wp-content and wp-includes) plus a bunch of .php files that also start with wp and then a number of miscellaneous files.
  • Download this entire directory into your local www directory. This might take some time, especially if you have been blogging for a while, have many plugins/themes and/or have uploaded a lot of files.

You can already perform steps 4 to 7 while the download continues.

Step 4. The Database Connection

In the WWW directory, open the file “wp-config.php”. You will see a number of lines that start with “define”. There’s one that defines the name of your database, it’s “DB_NAME”. Write down the name after that. By default it’s going to be “wrdp”, but this can vary. Also write down the values for DB_USER and DB_PASSWORD. You may have entered those at some point but might have forgotten them. Or they could be autogenerated when WordPress was installed.

Step 5. Export the database

Fire up phpMyAdmin on your remote host.

  • In the right part of the screen, you’ll see a number of tabs.
  • One of those is “Export”. Click that one.
  • You’ll see a screen divided into two sections: “Export” and “Options”.
  • In the “Export” section select the database name that you wrote down in step 4.
  • You don’t need to change anything in the “Options” section.
  • If you have a large database, select “gzipped” compression at the bottom of the screen. This can reduced the file size by a lot (mine was only 30% of the original, uncompressed file)
  • If you like, you can pick a nice name for the download.
  • Click “go” and remember where you save the file.

Step 6. Import the Database

Now we are going to import this file into your local database.

  • Fire up phpMyAdmin locally. Again, your AMP distributions will come with a shortcut to it. On Ubuntu you’ll find it at http://localhost/phpmyadmin/ by default.
  • This time pick the “Import” tab. It’s right next to the “Export” one.
  • Browse and select the file you just saved.
  • Press “go”.

Step 7. Set Up the Database User

Now we need to configure the WordPress database user. Remember you wrote down the name and password in step 4.

  • In the left section of phpMyAdmin, where it shows the databases, you should now see your imported WordPress database.
  • Click on it and it will show the tables in that database.
  • Now click on the “Privileges” tab.
  • Enter the username and password.
  • As host enter * or localhost.
  • Check all privileges (this will give global privileges, you could also give the user only access to the WordPress database. Since this is a local test system I’m not too worried about strict security, but keep this in mind)
  • Click “go” to create the user.

Step 8. First Test

Surf to http://localhost

You should see the blog appear, but you might notice it downloads all images from your original blog site. All links will also still point to the Internet, not to the local site. You won’t be able to log into the administration.

Step 9. Converting to Localhost

You didn’t leave phpMyAdmin, did you?

  • In the left column, click on your blog database (if it isn’t already showing)
  • Browse the “wp_options” table (it’s the first tiny actions icon)
  • Find the two options with option_name “siteurl” and “home”. There are many ways to do this, phpMyAdmin has a search function or you could change the SQL query if you know what you’re doing.
  • Change both options (with the little pen icon) so that their “option_value” reads “http://localhost”

Step 10. You’re Done

That’s it. You now have a fully functioning local copy of your WordPress.org blog.

Common Issues

When importing the database you receive an error that the file is too large.

In many cases, it might be beneficial to first clean up your database. Also make sure you enable gzip compression. If none of those help, you will need to change the default PHP file upload limit.

Categories or article links don’t work

Depending on your permalink structure, you need to have the “mod_rewrite” Apache module enabled. I’m not sure why, but this isn’t always on by default. There are numerous articles about it if you Google. For instance here’s a howto for Ubuntu.

Can’t add/configure plugins and themes and other permission issues.

Again, depending on how your installation is configured, the Apache/PHP process may not have permissions to change or add files in your WWW directory. If you don’t care about security, I suggest a “chmod -R 777 *” in your WWW directory. If you do care, find the group that the Apache process runs in and give that group write access to the entire WWW directory.

Something else

I haven’t run into this issue, but I can imagine there are plugins that won’t like to be moved to a different server. If you see strange issues, try to disable your plugins and enable them one by one. If you find the culprit, maybe you need to change its options in the wp_options database table.

Conclusion

Having a full copy of your blog on your own computer is a great resource to experiment with new themes or plugins. Although it might look daunting, once you’ve done this procedure, you won’t know why you didn’t try this earlier.

If you’re not very technical, or don’t feel like going through all the steps, I offer a $50 service for creating a VirtualBox Ubuntu image. Feel free to contact me for more information, or you can go straight to PayPal (VirtualBox setup is included).

(why buy from Streamhead?)