Bring Your WordPress Blog To Local Server For Testing Environment

As a WordPress blogger, plugin developer, or theme designer you should have a local server for a testing environment. In Ubuntu you can easily install Apache and MySQL as they are bundled in the default installation CD. In Windows you can use XAMPP as a handy web server (you can refer to my previous post Local Server For Testing Environment With XAMPP On Windows for more details). You can also use XAMPP for Mac. But the point is you need a local server environment for designing, developing, and testing your WordPress blog before going live.

So if you already have a live self-hosted WordPress blog, it is highly recommended that you use the current server data and files to test new plugins, new themes, or whatever. To use the current server data, you need to download the whole database and files to your local server. I’ll provide step-by-step instructions to make an exact mirror of your live WordPress blog on a local server installation.

Here is the step-by-step guide to bring your WordPress blog to a local server for a testing environment. I’m assuming you use cPanel, as most hosting servers use it.

Download database file

  1. Log in to your server cPanel and go to Databases > phpMyAdmin.
  2. It will open phpMyAdmin in another tab — select your WordPress database.
  3. Choose the Export tab and leave all the default choices.
  4. Check the “Save as file” checkbox and press the Go button.
  5. It will take a while to download your database into a single SQL file.

Download WordPress files

  1. Still in server cPanel, choose Files > File Manager, choose your WordPress installation folder, and click Go.
  2. The file manager will open in another tab.
  3. Usually your WordPress files are under the public_html folder, but if you installed your blog in a subdirectory (example /blog), then it will be under the blog directory.
  4. Compress public_html or the root of your WordPress files to a gzipped archive.
  5. Download the compressed file via an FTP client.

Extract the WordPress files

  1. Now we are working on your local computer.
  2. Move the downloaded compressed file into your web server default directory — usually it’s under htdocs.
  3. Create a subdirectory under htdocs and call it anything you want — in this example I use “blog”.
  4. Extract the compressed file to the blog directory.

Import database file

  1. Open phpMyAdmin — it’s usually at http://localhost/phpmyadmin, but if you installed it differently you should know where it is.
  2. Create a new database — I called it “blog”.
  3. Choose the blog database and go to the Import page.
  4. Select the downloaded database file and import it.
  5. After it finishes, go to the wp_options table and find “site_url” and “home” in the options name column.
  6. Change them to http://localhost/yoursubdirectory — in this example it would be http://localhost/blog.

Configure WordPress

  1. Open the blog folder and open wp-config.php.
  2. Change the database name, database username, and database password. In this example I’m using: database name: blog database username: root database password: toor

Okay, now you can log in to your WordPress admin (wp-admin) using the same username and password as on your server. Set the permalink to use the default permalink, as you don’t need pretty permalinks on your localhost. Then you can delete your .htaccess, because sometimes it won’t work in a default XAMPP installation. It’s also recommended to deactivate some plugins you don’t need, such as WP Super Cache, HyperCache, DB Backup Manager, Akismet (no one will spam your localhost), WP Stat, other stats plugins, and any other plugins you feel you don’t need.

Now you have a complete mirror of your WordPress blog on your local server. You can play with it as you like, and test any plugins before going live. Test and tweak your themes before applying them. Do whatever you want to do in your local testing environment. If it breaks, revert back to the old database and files.