Cloning WordPress from live server to localhost

In this tutorial we will go through how to clone a WordPress site from a live server to localhost (even with large databases).


Copy files

First you need to copy all files from the live host and export it’s database.

  1. Download all files from the live site to your MAMP htdocs folder
  2. Log in to the phpmyadmin of the live site, and export the database

Increase file upload limit

If you have a large database, you will need to import via the Terminal instead of phpmyadmin. First you need to increase the file size limits of MAMP.

Find your php version by opening MAMP settings, and look for the current version in the PHP tab:

Image.png

Open /Applications/MAMP/bin/php/php7.4.2/conf/php.ini file (replace the number at the php part for your php version) and edit the following values:

upload_max_filesize = 1024M post_max_size = 1024M max_execution_time = 3000 memorylimit = 512M

Create database

Open the Terminal app, and type this:

/Applications/MAMP/Library/bin/mysql --host=localhost -uUSER -pPASSWORD

Replace the USER with your localhost username (typically root) and PASSWORD with your localhost password (it is root by default on Mac). If you did everything ok, the command prompt will change from your username to “mysql>".

Image.png

/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -pfelix

Before uploading the database, you need to create the same database name and use it in the mysql Terminal prompt. Enter the following command to create a database with the name test_db.

CREATE DATABASE test_db;

Remember you should create exactly the same database name that you download in step 2 from live site. Now enter the command below to check if the new database was created successfully:

show databases;

Image.png

Finally enter the command below to use the newly created database for importing:

use test_db;

You will see a messages what says that Database changed

Image.png


Import database

Enter the command below to import the database you have download from live server (in step 2.)

SET autocommit=0 ; source /Applications/MAMP/htdocs/test_db.sql ; COMMIT ;

Don’t forget to replace the path after source to the path where your importable database is located. Finish typing the command and hit enter. Terminal will start dumping the database and show query running status.

Image.png

After the Terminal dumping is finished, open phpMyAdmin and check if the database was created successfully. In our example, we have test_db successfully uploaded with the tables.

Database-Tables-Uploaded-Successfully-.png


Import Large MySQL Database in phpMyAdmin in MAMP

Replace URLs

Now that you have uploaded live site’s database to local server but the tables will still have live site’s URL references instead of localhost which you need to change it. Copy the below query and replace the site name and the localhost name your own URL.

UPDATE wp_options SET option_value = replace(option_value, 'https://www.yoursitename.com', 'http://localhost') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET post_content = replace(post_content, 'https://www.yoursitename.com', 'http://localhost'); UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://www.yoursitename.com','http://localhost');

Go to the phpMyAdmin section of your localhost site and select the database. Click on the “SQL” tab and paste the query in the box and hit “Go”.


Replace site files

Copy the plugins and themes folders from the live site backup, and simply replace with the ones in your localhost install.


How to Move Live WordPress Site to Localhost?

or…. alternatively you can use WP All In One Migration plugin ⭐️⭐️⭐️⭐️⭐️


Add Comment

Comment submitted

Thanks! Your comment will appear shortly. Please reload the page.


Tags