There are applications like MAMP and WAMP used to create a local server environment. This helps to install packages like WordPress so that developers and site owners can build their site in local PC or Mac. Once the local site is ready, it can be easily moved to the live server. But over the period of time your live site may have lot of deviations compared to the localhost site.
At this point you may want to sync the live site’s content to local site so that you can test plugins / themes/ WordPress version updates on a local site before updating on a live site. Though there are plugins which can speedup the backup process, in this article we explain how to manually move live WordPress site to localhost environment. If you are looking for setting up local WordPress site then read our separate article on how to install WordPress on your Mac using MAMP.
Summary: Move Live WordPress Site to Localhost
Before we go to the detailed process here is a summary of the entire process for moving your live site to localhost environment:
- Use FTP client and download all your live WordPress site files, generally available under “/public_html” folder.
- Login to your hosting account and export live site’s database from phpMyAdmin section.
- Login to phpMyAdmin of your localhost using the application you used to install WordPress locally and create a new database.
- Import live database file downloaded in step 2 to localhost server.
- Run query to replace all occurrences of live site’s URL with the localhost URL.
- Replace localhost site’s files with the live site’s files from step 1.
- Edit “wp-config.php” file and change the database name to new database name as created in step 3.
- View localhost site and login to localhost WordPress admin dashboard to see all live site’s content is available.
You can setup localhost WordPress site using port 80 or 8080. If you use 80, the URL will be http://localhost and for 8080 the URL will be http://localhost::8080. In this article, we will explain using port 80, if you use 8080 remember to use the correct local site URL.
Learn WordPress: Check out 500+ free WordPress tutorials.
Step 1 – Download Live WordPress Site Files
Launch FTP client like FileZilla, connect to your hosting server and download all WordPress files of a live site to local computer. Generally files will be available under “/public_html” folder unless you changed it to another directory during WordPress installation. The entire download may take a while based on the size of your site. Hence we recommend to do this step first so that you can do further steps in parallel.
In FileZilla first choose local site’s location where you want save the files. Under remote site section, select the files and choose “Download” option by right clicking. This will download all selected files to your local computer.
If you are looking for FileZilla tutorials, read our article on how to configure FileZilla, setting up FTP account in Bluehost and connect FileZilla to Bluehost FTP server account.
Step 2 – Exporting Live WordPress Site’s Database
The next step is to download the SQL database file of your live site. Login to your hosting account and go to the cPanel. Click on the phpMyAdmin icon and login to your phpMyAdmin section. Note that some hosting companies like SiteGround offer custom solutions instead of cPanel. You should be able find phpMyAdmin as it is a standard database management tool. Select the correct database and click on the “Export” option.
- Choose “Custom – display all possible options” as “Export Method”.
- Select all database tables (you can ignore the tables which you don’t want to export by deselecting them).
- Select output compression as “zipped” or “gzipped”.
- Choose format as “SQL”.
Click on “Go” button at the bottom to download the SQL database file in a compressed format to your local computer.
Note: We recommend export the database by ignoring security and caching plugin tables. These plugins may cause problems while uploading it in the local environment. In most cases, these types of plugins are not required in local environment or you can export the plugin settings from live site and import it on your local site after reinstalling the plugins.
Step 3 – Creating a New Local Database
Similar to step 2, login to phpMyAdmin section of your localhost with the URL “http://localhost/phpmyadmin/” and create a new database with the same name as live site’s database.
Step 4 – Importing Live Database to Local Site
Now select the newly created database and then click on the “Import” option. Choose the live site’s database downloaded in step 2 and upload to local server.
The import will work when you have smaller database size. If your live database is bigger than 32MB in size (or as limited by maximum file upload size on your site) then importing zip file from phpMyAdmin will fail. In such case, you may need to upload the database from command line. You can follow the instructions in this article on how to import large SQL database for MAMP in Mac.
Step 5 – Replace Live Site URL with Local Site URL in Tables
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 with 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.
If you see the “Simulate query” button, click on it to see whether the query will replace the URLs. Sometime you will not see the “Simulate query” button. Just click on “Go” button to run the query to replace live site URL with localhost URL. Remember to note the following points:
- Ensure to use HTTPS, if your live site URL is SSL protected.
- Localhost URL should always be with HTTP.
- WordPress tables generally starts with “wp_” prefix. But if you have changed with other prefixes, then replace the table names in the query as per your prefix.
You will see the result indicating how many lines are changed in the tables after the successful execution of the query.
Step 6 – Replace Local Site Files with Live Site Files
Next step is to replace local site’s files with the live site’s files downloaded in step 1. The simple way to avoid mistakes here is to change the existing local folder name with the suffix “_old” and then create a new folder with the same name. Paste all live site’s files inside the new folder.
SEO Offer: Optimize your site with Semrush Pro special 14 days free trial.
Step 7 – Configuring Database Name in wp-config.php File
If you open your localhost site now it will probably show the message “Error establishing database connection”. Locate and open “wp-config.php” file in local server and replace the database name with the correct name as you created in step 3. Generally the username and password are same as “root” (unless you changed it) and change it accordingly.
Step 8 – Check Your Localhost Site
Login to localhost WordPress admin dashboard and check the settings.
- The sidebar widgets will not be imported from the live site. So you should manually add the sidebar widgets in localhost site.
- Plugins having single domain license key may not work on the local site as it is validated with the live site.
- Some of the plugins like caching and security plugins may not work in local environment. Either they will be automatically deactivated or you should manually deactivate for the localhost site to work properly.
- If you have the absolute URLs used on footer and menu items then you may need to manually change them to local site URLs.
We hope the article helped you to move your live WordPress site to localhost. As mentioned, we recommend to ignore the caching and security plugins and related tables when exporting the live content. In addition, the page builder and licensed plugins may also stop working on the local environment. You can also try other options like using staging site if you are using siteGround or Local By Flywheel.
Thanks for this! It was really useful. The step 5 URL replacement created some difficulties though, which I pinned down to URLs included within serialized data. If the length of the new URL doesn’t match that of the old one, errors abound. I fixed with another search and replace, using the correct string length, but it might be better to advise people to use the Better Search & Replace plugin, which includes support for serialization.
The steps you have given worked and got me to the website home page but it was broken for all the blog pages.
I was also able to login into my site admin account and did a cross check on the permalinks for the blog pages. This links are also correct for all blog pages.
And I did follow all the steps you have given including the database updates
There are many possible reasons for this:
1. Disable security plugin if you are moving it from live site.
2. Disable caching plugin in local environment.
4. Make sure the media upload directory is readable from localhost (this is required especially any plugins store files that are needed for page loading).
Hope this helps.
I’m confused. If mySQL is served at port 8888, then does the local site URL in step 5 be changed to http://localhost:8888, or still http://localhost? And how about DB HOST in wp_config? Should it be localhost, or localhost:8888?
DB host should always be localhost.
Localhost URL will change with :8888 prefix, if you use that port. You can to use the correct URL in replacement queries.
I used Local by Flywheel to go through this process. Here’s a problem I encountered: Inside the Local by Flywheel app, if I click on View Site button, it directs to my live domain in stead of the localhost site. However, if I click on the Admin button, I got directed to the login page for Wordpress. After logging in successful, I was able to access the Wordpress admin interface, and then went to my localhost site with no problem.
What could be the problem? The fact that I was able to access the localhost through a roundabout way means that there’s nothing wrong with config, or database. I appreciate any help I can get.
Check out the article whether it helps: https://www.webnots.com/move-live-wordpress-site-to-local-server-using-local-by-flywheel/
I created a subfolder named localwordpress under httdocs, then placed all of the Wordpress files under this folder. I went to localhost/localwordpressI, but I got a Page Not Found error. What should I do? Guess I shouldn’t have attempted this when I didn’t learn about php and mysql properly.
Hi I think you need to change the sql query to read the localhost url.
your URL is localhost/localworpress
the query = UPDATE wp_postmeta SET meta_value = replace(meta_value,’http://www.yoursitename.com’,’http://localhost’);
Think you need to change to
UPDATE wp_postmeta SET meta_value = replace(meta_value,’http://www.yoursitename.com’,’http://localhost/localwordpress’);
you would need to change all 3 queries though.
Also did you test the initial install of worpress in the subfolder?
step 5 won’t work for me…for some reason it imports the database and creates sitenamelocal tables inside…then my front page is blank except for the site logo and footer..and says page not found…
Am I correct to understand that if I follow the procedure above, I will be able to update my website on my PC and then upload it on the webserver each time? Or do I have to following the same procedure everytime that I want to update the website?
Firstly, thank you for putting out this article.
I’m stuck at ‘Step 5’. Will you please help me with this.
I get the error “#1146 – Table ‘uberkarm_wp.wp_options’ doesn’t exist”. I’ve tried for a few hours now to play around with things, search the internet, and even delete and reinstall my test wordpress site, but still haven’t been able to find a solution.
I’m using SiteGround and CyberDuck.
If you have changed the table prefix from wp_ to anything else then you should use that prefix in the SQL query to replace the URLs.
Thank you! I got it to work.
I ran into another problem.
I finished all the steps and when I check the local site the WordPress theme appears, but without content. I am then redirected to the online site when I click on any other pages.
When I ran the SQL query it only found 6 things to change. I made sure the ‘wp_’ was correct.
This is a very basic WP site I created to learn how to transfer it over to a local host. It only has a few pages and a few pictures (99 mb).
Can you give me some advice please?
you are a life saver!
Thank you very much for the detailed tutorial, it worked like a charm.
Thanks for this. I did all the steps (a couple times) and can see the site but it will not let me log in. I checked the user name and password a couple of times. And when I fire a reset password, I do not receive an email.
You can’t reset password in localhost as the local server by default can’t handle PHP email functions. Go to phpMyAdmin section of your localhost site and reset the admin password by looking the admin id in “wp_uers” table. You can change the password under “user_pass” field and select the function as MD5 from the dropdown. Click Go button to save your changes and try to login to localhost site with the new password.
I wanted to have a replica of my live site on one of my test domain/subdomain i have and I have used this blog few days before and did all the steps perfectly and it worked fine.
Now i want to have same site replica on another subdomain, and i did all the steps again and all is ok. But when i try to access the wp dashboard to make few changes, i am getting the url as page not found.
I am not able to see the wp login page to access.
Please help me to solve this.
If one case worked fine, another case also should work from the steps perspective. Check the installed plugins and deactivate all plugins and try to login. You can change the plugin’s folder name to “old_xxxx” to deactivate.
Your tutorial is great.But the thing is i did all the steps correctly.And i can login to the admin dashboard and also i can visit the home page but from there if i want to go to next page it goes to the live page(server page) and not the local page…i did change the links in wp-options and wp-posts and wp-postmeta…i did all the updates but from the home pages it goes to the live page address….
If the database is updated with localhost URL then no possibility it can go to live site. If you are using absolute URL in sidebar/footer widgets then it will be linked to live site. You should change the widget content on localhost.
Hi, thank you for this beautiful little guide. One question here:
Step 1 – Download Live WordPress Site Files
Step 6 – Replace Local Site Files with Live Site Files
Is it not just fine to skip step 1 until the database have been set-up and then download all the live repo?
Or perhaps just download it on step 1 and leave it like that for database connection?
What’s the point to download it twice? I just don’t get it :/
Many thanks, Frank.
The reason is clearly mentioned in step 1 – downloading the entire site with FTP will take many many hours depending upon the size.
If you have very small site with few images then you can do it later.
if my live site has SSL certificate, can i still shift it locally using mamp or must i upgrade to mamp pro for localhost to load the SSL? Or can i load the live ssl site without https on my localhost?
If you want to use https on localhost then you should use self signed certificate. But this is a tedious process to setup and modify the Apache configuration file. You can check out this article for more details.
For http access, you should replace all the occurrences of the live site with http://localhost as explained in the article.
Everything went well, and the home page displays perfectly on localhost. BUT… when I try to go to any other page I get this:
The requested URL /jymusic/about/ was not found on this server.
The URL update queries are okay as far as I know. This what I entered:
UPDATE wp_options SET option_value = replace(option_value, ‘http://jymusic.com’, ‘http://localhost/jymusic’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;
UPDATE wp_posts SET post_content = replace(post_content, ‘http://jymusic.com’, ‘http://localhost/jymusic’);
UPDATE wp_postmeta SET meta_value = replace(meta_value,’http://jymusic.com’,’http://localhost/jymusic’);
I can’t figure out why this is happening?
Same here… Anyone can help?
I have the same problem, I change the permalink settings, from “Custom Structure” to “Post Name”. It’s solve the problem.
Changing permalink settings and reset back is the simple solution that will create the entries in .htaccess file for the links to work properly.
Hi, I do all 5 step. I renamed my file .htaccess for something else.
I saw my first page (Shop), and I can acces in the admin(everthing is there, I saw all my content pages and products in both languages FR/EN). But when I want to click to see other page from my menu. I can’t access. I saw the url is the localhost ex: (localhost/styly.ca/temoignages/). But I can’t access. I feel I’m so close. Sorry for my mistake in english. Is there a part that I forgot to do?
The localhost URL you mentioned is not correct, you can’t have two domain names in the URL. The localhost should replace your domain name style.ca and the correct URL should be “localhost/temoignages/”.
Probably on step 5, you have done the replacements of site URLs in “wp_options” correctly (this allows you to login to localhost). But you might have done “wp_posts” with wrong replacement which leads to wrong URLs in the content.
Oh it’s not all 5 but all the step I do correctly. It’s not a problem from my domain localhost/styly.ca. I asked a friend to help me. He send me this link. http://www.anmsaiful.net/blog/php/enable-apache-rewrite-module.html, and after everything worked. And I went to parameter / setting and save the permalink. My problem is solve. Thank for the reply.
Hi, thank you for this, it has so far helped a lot but i have hit a wall. I have completed all the steps but instead of my site, i get a link saying ‘skip to content’ which directs to /mylocalurl/#content/
I tried going to /wp-admin/ to log in in the case it was a plugin i needed to activate but this 404’d.
Any help would be greatly appreciated.
First you can go to the document root and change the name of plugins to disable them (looks you are using some plugin to show the content).
Ensure you have done step 5 correctly to replace the site URL with localhost then you should be able to login to localhost.
Hi, i did follow your steps. But still it did not work.
Then i edit [wp_option] in phpmyadmin wordpress database, there i changed the URL to localhost it worked!!.
But thank you for your help too!!
This is step 5 – replace all live site URLs with localhost.
Hi and thnx for your great tutorial.
I did everything as described.
– Wordpress runs without any problems
– the imported “live” database shows all content
But there are
– no templates
– no styles
and finally … no Wordpress any more (that worked perfectly bevore changing database-Name and changing files.)
Do you have any idea (guess you will)
Best from Berlin
Thanks for reading. Based on the screenshot you are trying to open a page “localhost/wordpress” and getting “404 page not found” error. Your localhost site homepage should be just “http://localhost” (without “/wordpress”).
If you have done the database / files import correctly then it should work fine. Login to the localhost admin panel and check required theme and plugins are active.
PS: the screenshots you attached were deleted as it was showing the database details.
Where you say to “Replace Live Site URL with Localhost URL” I’m not following.
I’ve cut and pasted the Update code into my SQL section within my database, but I am not sure what to do from here?
What is my LocalHost URL?? The name of the database after localhost? EG http://localhost/“nameofmydatabase”?
UPDATE wp_options SET option_value = replace(option_value, ‘http://www.yoursitename.com’, ‘http://localhost’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;
UPDATE wp_posts SET post_content = replace(post_content, ‘http://www.yoursitename.com’, ‘http://localhost’);
UPDATE wp_postmeta SET meta_value = replace(meta_value,’http://www.yoursitename.com’,’http://localhost’);
You need to replace “http://www.yoursitename.com” with your live site URL. In general the localhost URL should be “http://localhost” as mentioned in the query. But it depends on your configuration and can also be like “http://localhost:8080”.
Great post. Worked beautifully for me.
The only issue I had was in importing the database because the SQL file was too large. If this happens to anyone, you can get around it by doing the import from the command line:
$ mysql -u root -p
mysql> use your-database-name;
mysql> source path/to/your-backup-file-name.sql;
Hope that helps someone.
Thanks for the inputs, it should definitely help for those having larger DB file.
I get the following error when running the query
UPDATE wp_options SET option_value = replace(option_value, ‘http://www.tier1consultant.com’, ‘http://localhost’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;
MySQL said: Documentation
#1046 – No database selected
Open new phpMyAdmin window
You should have created a database with the same name as your live site’s database and then imported the live database before running this query.
I’m having issues running the SQL Query to change the site names. I’m pretty sure I’m running it correctly, but it returns with ‘MySQL returned an empty result set (i.e. zero rows)’
I am now getting a 500 error that I assume has to do with this…please advise.
I’ve followed your excellent guide, have copied two of my websites to my local computer and am now shifting between them in my www-folder in WAMP-server, moving files back and forth. I have some issues though:
1. At first it didn’t work, then I found out that I had to remove my htaccess-file first, originating from my live host – or else localhost wouldn’t show anything!
2. On one of my websites (www.zlight.dk) everything works properly in localhost – until I press one of the menu buttons which points to a live link. And suddenly I’m on my live site, which kinda confuses me, but I guess that’s what it is.
3. On my other website (www.osleder.dk) I’m not even allowed to ‘stay’ in localhost – it immediately jumps to my live site, when I write “localhost” in my browser. That is, I’m immediately directed to http://www.osleder.dk.
How do I get around these issues?
1. At least in Mac with MAMP still .htaccess file is needed especially if permalink is used, otherwise all pages are showing 404 not found. But we also noticed in WAMP, .htaccess file needs to be deleted as you mentioned.
2. Please check you have any plugins creating separate tables. In step 5, only three tables (wp_posts, wp_options, wp_postmeta) are redirected to a live site, if there are links in other tables then still it will be pointing to a live site.
3. This means the site URL is still pointing to live site in “wp_options” table. Check you have done step 5 – replacing the live site’s URL with localhost URL.
Hope this helps.
Please, how can one resolve the second(2) point, after locating the plugins creating separate tables?
Go to phpMyAdmin and select the database to see all tables available. If the table is created by a plugin you can identify with the name (for example if Woocommerce is the plugin then the table name will contain the word “woocommerce”). Use similar query as mentioned in step 5 to replace the site URL to localhost URL.
UPDATE your-database-table-name SET post_content = replace(post_content, ‘http://www.yoursitename.com’, ‘http://localhost’);
Chrome report me: “The web page is not available. ERR_CONNECTION_REFUSED”
Why? I don’t understand. ;(
Ensure you have configured the ports correctly in the local environment. This could be the reason for the error.
This is very useful and now i backed up my whole site locally without any plugin.