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:

You need to add in another 2 lines:

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

27 comments

  1. I am glad that it is useful to you. I used this method all the time so that I can test any changes on local server before making it live.

  2. This does not work for me. Have followed the setup to the letter. When I go to http://localhost:8888/wordpress/wp-login.php it displays the WordPress 5 minute install screen. Have tried several times. And if you do the install it adds the default WordPress fields to the database above the fields from my live site.

  3. Have done all that you describe, but when I attempt to start my local site (XAMMP based) what I get is my live site. have checked that the additional two lines in wp-config are present (does their position in the order of instructions matter?)

    Would appreciate you telling me what I have done wrong.

    Ed.

  4. have fixed the problem below, and all is functioning Except the 'view page' feature when logged in and working on individual pages. The only way i can view a page change is to access the entire site and select a page.

  5. Thanks for the good article Damien. When I do this, I can open my first page, but then all the links I click direct me to the live site. Also, my sitenamewp-admin link doesn’t work, so I can’t login to my admin page. Yikes!!

    • Mike,
      Did you change the information in the wp-config.php to reflect the URL of your local server?

      For example, in XAMPP, if all your wordpress files are stored in the “test” folder, you should include the lines:

      define(‘WP_HOME’,’http://localhost/test’);
      define(‘WP_SITEURL’,’http://localhost/test’);

  6. Hi! I need some help, I do exactly as yo say before, and i clone my online site to my local xampp. I can log in, make a new post, etc. But when I try to see it, it only shows me a white page, completly empty. No code at all. Can you help me please? Thanks!!

  7. Me again… I solve it! It was just a theme problem, I pick another one and walá! Great tutorial this one of yours! thanks!

  8. Damien,

    Thanks… this little sentence helped solve my headache for the day:
    “To make the permalink work properly, you will need to regenerate the permalink structure in the Permalink setting page and edit the .htaccess file)”

    But is & where do I find the “.htaccess file”?

  9. My images don’t seem to work though, has that have to do with .htaccess file? A files have been copied into the right path.

    • It is probably the image path is not set probably. Right-click on the image and view the image url, see if it is pointing to the previous server or the localhost.

  10. Yep, you can also cpanel into your existing server installation and SSH tar your entire root directory (or with Putty assuming you use that).

    Goto phpmyadmin , export your wordpress database. goto localhost/phpmyadmin (assuming youre on xampp you already have this installed) and create a new database and user for your site, import your exported .sql file into that database. You’ll then extract your tar/zip into your localhost wordpress directory, then edit the wp-config with your new database and

    define(‘WP_HOME’,’http://localhost/’);
    define(‘WP_SITEURL’,’http://localhost/’); in your wp-config after define(‘DB_COLLATE’, ”);

    name wp_home and siteurl to the new localhost url to your localhost url and you should be set, it should use the same admin login as your live version. If it doesnt, goto your database table ‘wp_users’ within localhost/phpmyadmin inside your wordpress database and you’ll see the logins that correspond with your wordpress install.

    Edit the admin one and goto ‘user_pass’ , then click the ‘Function’ dropdown and select MD5 , and then to the right of it is your password field… just set your password and when you update, it’ll automatically place the password into an md5 format for wordpress to decrypt and read for you.

    Hope this helps and thanks for good article…

    • Thanks for your instructions. The steps are similar, except that you tar the whole WordPress directory. Personally, I prefer to just backup the wp-content folder. It contains everything you need to restore your site.

  11. Hi Damien. THANK YOU – You saved my LIFE today with this one…no, really! :-)  Can I ask for some more help from you? Can you please detail how to take the local / dev site and deploy that to a STAGING server on the same server as the “live” site? Once I have changes made locally, I need to pass them to the client for review. Once approved, I’ll then need to take the STAGING site and make it the “live” site. Is it possible to walk us thru those steps? 

    • The steps are exactly the same. You just need to import the database to the server database, change the WP_HOME and WP_SITEURL to the staging domain. That’s it.

  12. Damien…thanks for the tutorial. I got it to work, kind of…lol. The theme is broken, as is a bunch of my plugins. I did vast customization on the theme, which is not present on the localhost. The whole reason I am doing this is to make adjustments to the existing theme offline so I can play around with it. Do you know why the theme and a lot of the plug-ins are not working? I followed the instructions exactly. Thanks… Jason.

    • Did you copy the theme and plugin file down from the server to the localhost? The copy used in the localhost must be the exact same copy used in the server.

  13. Hi, I wonder if you can help me.

    I had set up my site locally and exported it to my live site.  I want to make some changes to it locally, but now when I try to run my local site, I get a message saying “Error establishing a database connection”.  What am I doing wrong?  I know that it’s pointing to my live site, but how do I maintain my local site so I can make changes to it without it going live until I want it to? 

    • In your localhost environment, you have to change the database setting in wp-config.php file to point to the localhost database. Alternatively, if you want to connect remotely to the live site, you need to make sure the web host allows this and the database setting in the wp-config.php file is configured properly.

Comments are closed.

Sponsored Stories