How to Clone Your Live WordPress Blog to a Local Server

clonewp-mainBloggers, 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



Print this pageSave as PDF

Damien Oh is the owner and chief editor of Make Tech Easier
  • Armorer_4star

    Thanks Damien, thats great information & saved me heaps of time.

  • http://maketecheasier.com/ Damien Oh

    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.

  • milesj

    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.

  • http://maketecheasier.com/ Damien Oh

    Did you notice that you are using http://localhost:8888 while the URL you place in you wp-config.php is http://localhost?

    Change the following in your wp-config.php file
    define('WP_HOME','http://localhost:8888/wordpress');
    define('WP_SITEURL','http://localhost:8888/wordpress');

  • meongroup

    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.

  • meongroup

    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.

  • Mike

    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!!

    • http://maketecheasier.com/ Damien Oh

      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‘);

      • Katy

        These 2 lines just saved me a lot of headache. Thank you!!

        • http://maketecheasier.com/ Damien Oh

          Yes, that 2 lines are often a lifesaver in many cases. I am glad that it is of use to you.

  • Cerohumano

    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!!

  • Cerohumano

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

  • Theficx

    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”?

  • Theficx

    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.

    • http://maketecheasier.com/ Damien Oh

      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.

  • http://www.ryandennler.com Ryan Dennler

    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…

    • http://maketecheasier.com/ Damien Oh

      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.

  • Allie

    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? 

    • http://maketecheasier.com/ Damien Oh

      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.