How to Clone Your Live WordPress Blog to a Local Server

Bloggers, have you ever been in the situation where you want to make changes to your site (such as changing of theme, installing new plugins etc), but afraid that it will break your site? A lot of time, we wish to implement some changes and see how it looks like on the live site, without actually making it live. In such cases, the best solution is to create a local server (aka test server) and clone your live site to the local server. In this way, you can first test out the changes on your local server and make it live only when you have confirmed everything is working well.

What you will need:

  • a local server application (we recommend XAMPP since it is the easiest to use and it works for all platforms)
  • a copy of the WordPress software (download it from WordPress.org
  • a copy of your existing WP blog database
  • a FTP program (We will be using Filezilla, but you are free to use your favorite application)

Let’s get started.

Installing WordPress in your local server

I won’t go into much detail here since we have previously written plenty of articles on this. Check them out:

How To Install WordPress MU In Windows Localhost (With XAMPP)

Setup a PHP/MySQL Environment on Windows The Easy Way

How to Install and Test WordPress on Your Mac

Note: Resume this tutorial only after you have installed WordPress in your local server.

Backing up your live WP blog

You will need to get a backup copy of the database of your live WP blog. This can be achieved in two ways: plugin or phpMyAdmin.

Plugin
There are several plugins that can backup your database. My favorite is WP-db-backup plugin. You can also use WP-DBManager plugin.

Install the WP-DB-backup plugin and go to Tools -> Backup in your WordPress dashboard.

Check all the tables name.

clonewp-backup-database

Select “Download to computer” and click “Backup now!”.

clonewp-download-database

The backup process will begin and it will prompt you to download the sql file when it is done.

phpMyAdmin
Login to your web host cPanel and click on the phpMyAdmin icon.

clonewp-phpmyadmin

In the left pane, click on your WP blog database.

clonewp-phpmyadmin-db

Click the Export button.

clonewp-phpmyadmin-export

Scroll down to the bottom of the page. Check the box “Save as file“. Also check “gzipped”. Click Go.

clonewp-phpmyadmin-savefile

Restoring the database in your local server

Start your local server. Open a browser and go to “http://localhost/phpmyadmin”. Create a new database.

clonewp-create-new-db

Next, click on the “Import” button.

phpmyadmin import button

Navigate to the location where you save the database file. Click Go.

clonewp-import-file

This will import your WordPress database to your local server. If your database file is more than 2MB, you might need to increase the “upload_file_limit” variable in the php.ini file.

Configure the wp-config file

In your file manager, go to the WordPress folder within the htdocs folder. Open your wp-config.php file in a text editor and change the following:

//unless you have changed the setting, else the default will be as follow
define('DB_NAME', 'wordpress'); //change this to the name of the database you have created earlier
define('DB_USER', 'root'); 
define('DB_PASSWORD', ''); //no password by default. Change this if you have added password during installation
define('DB_HOST', 'localhost'); //99% you won't have to change this

You need to add in another 2 lines:

define('WP_HOME','http://localhost/wordpress');
define('WP_SITEURL','http://localhost/wordpress');

That’s it. You have successfully cloned your live WP blog to your local server. You can login to your dashboard via the link “http://localhost/wordpress/wp-login.php” and make changes to your test site.

Note:

  1. To make the permalink work properly, you will need to regenerate the permalink structure in the Permalink setting page and edit the .htaccess file)
  2. For better compatibility, you might want to replace your wp-content folder in the local server with the one in the live site.

Image credit: thatcanadiangirl