First, we’ll need to make a copy of your current WordPress blog. I’m going to assume you have access to the console at your hosting provider, or they at least have some type of backup provided for you. If you get your backup files a different way you can skip that step.

For a blog, we’ve got both the WordPress installation as well as the database, where the text of all your posts are actually stored. If you’ve uploaded images or files, they will be in your wordpress folder structure, so we really need both.

  1. Let’s get a backup of the database first. Connect to the server via SSH and run the following command:

Naturally you’ll want to substitute the uppercase text for the correct values on your installation.

  1. Make a backup of the file structure:

You’ll want to substitute the uppercase text for the root directory of your site.

  1. Copy the files down to your local Ubuntu machine. This can be done via scp, ftp, or however you feel like it. I’ll leave that up to you.

  2. Make sure you have apache, php and mysql installed. If you don’t, you can consult the other how-to guides on this site, or just type in the following commands at a terminal prompt:

  3. We need to create a database and import the original database that we backed up. Navigate to the folder that you downloaded the files to and run these commands:

sudo apt-get install php5

sudo apt-get mysql-server

sudo apt-get php5-mysql

sudo /etc/init.d/apache2 restart

  1. Make our local webserver point to the copy of WordPress we got off the production server. First, we’ll want to extract the tar archive that we created. You can do that however you want, but I prefer the command line. There is a utility built into Ubuntu to allow you to do so graphically if that’s the way you like to do it.

mysql -uroot DATABASENAME < dbbackup.bak

This will produce a directory structure similar to the one on the server you were on. We’re going to imagine that your site root directory is now in /home/username/wordpress/ for the purposes of this article. If you’ve extracted it elsewhere, then substitute accordingly. We need to add in the alias into apache, so open up the following file:

You’ll want to paste in these lines, and adjust the paths according to your system and the /directory you want the test blog to be available on.

  1. If you are using Permalinks, you’ll want to duplicate the same thing locally, and will need to enable mod_rewrite:

  2. Now we’ll need to edit the wp-config file to point to the local database. If you’ve been following along, these settings should work for you once you substitute the database name.

  3. If you are using the using WP-Cache caching module, navigate to your blog root directory and run these commands:

  4. One final thing left to do. The data in the database still has the wrong URL for your blog. The easiest way to fix this is by running a SQL statement against the database. Create a new text file named fixsettings.sql, copy the following lines into it, substituting your own IP address for localhost if you want other people to connect to you:

ln -s wp-content/plugins/wp-cache/wp-cache-phase1.php wp-content/advanced-cache.php

rm wp-content/cache/*

chmod -R 777 *

Now we’ll import that into the database:

Note that you should keep that file around, because any time you want to update your local copy with the latest blog posts, all you have to do is import the database backup file, and then re-run this fixsettings.sql file to make it point locally again. Definitely makes things a lot simpler, and you can eventually schedule a cron job to backup your production blog and pull it into your local machine on a schedule.

Now you should be able to navigate to http://localhost/wordpress/wp-admin/ and login with your regular username. You’ve now got a development copy of your blog!