Skip to content

How To Transfer A Live WordPress Site To A Localhost

After your website has been deployed to a hosting server, it’s not uncommon to keep making changes to your website. However, it’s never a good idea to do so directly while visitors still have access to it, for obvious reasons… 😅 Instead, you’re better off working on a staging or testing site from which you can eventually push your changes to your live site. In this tutorial, I’ll be showing you how to transfer your live WordPress site to a localhost manually. Not with a plugin, capiche?

Setting up a local WordPress site

Before we get started with all the migrating goodness, we first need to prepare a local WordPress site, which we can copy everything to. I’ve written an article on how to do so using XAMPP, if you’re interested. However, my preferred method of creating a local WordPress site is using Local By Flywheel (those guys really need come up with a better name 😐), a dev tool specifically for WordPress. It’s easy and convenient to use, and is able to set up your site in a matter of seconds. But even better… it’s free!

Once you’ve setup your local WordPress site, it’s time to start copying your live site! In this tutorial, I’ll be replicating all the steps with my website Chunk Bytes.

Copying your live website

Patrick meme from Spongebob Squarepants about simply moving a live WordPress site a localhost.
Patrick knows what’s up! 😉

In order to successfully replicate a WordPress website, whether it be locally or online, you will need three things:

  • The website’s database,
  • It’s frontend and backend files (such as HTML, CSS and PHP), and
  • It’s configuration file(s)

Exporting the database

In your website’s cPanel, head over to the Databases section and click on phpMyAdmin.

A screenshot of a phpMyAdmin interface with a database selected.
phpMyAdmin interface

Once you’ve accessed the interface, you want to first search for the database related to your website in the sidebar on the left. In my case it’s chunkbyt_wp649. After you’ve found it, select it and then click the Export tab at the top. Next, make sure you’ve got the Quick 🏃‍♂️💨 export method selected and export your database by clicking on Go.

Copying the site’s content

Next, we need to copy all the content that lives in the WordPress directory wp-content. To do this, access the File Manager under Files in your cPanel. From the home directory, enter the public_html directory and look for the wp-content folder. In order to download the entire folder, you’ll have to select it and click on Compress at the top, as well as choose Zip archive as the compression type afterwards.

A screenshot of the cPanel File Manager, showing the home directory.
File manager interface

Depending on the size of your folder, it may take a few minutes. ⏳ Of course, you’ll have to download the zip file once it’s done. After the download has finished, you may delete the file from the File Manager.

Copying the site’s configuration

Last but not least, we also need to copy the site’s configuration, which in this case lives in wp-config.php. Same as before, head over to the public_html directory and download the file to your computer.

Importing all the data and files

Awesome! We’re almost halfway there! In this part of the tutorial, I’ll show you now how to import all the data and files we’ve just collected, starting off with the database. 🤓

Importing the database

Head over to your local website’s database administration panel. In most cases, that will be phpMyAdmin again. However, in my case, Local By Flywheel uses a database manager called Adminer. Nevertheless, these steps won’t differ for you, regardless of what you use.

A screenshot of adminer, a database manager, of a local WordPress site. It shows an overview of all the databases.
Adminer interface

First, you need to create a new database. You may name it the same as the original one or give it a completely new one. Frankly, it won’t affect the process. After that, with your new database selected, import your sql file that we’ve exported from the previous section.

Before moving on, do make sure that a database user 👩‍💼 exists who has access and all the privileges to modify your newly created database. In particular, make sure to keep their name and password in mind. If you don’t have one, be sure to create one!

Moving wp-content to your localhost

Next up, unzip your file and move it to your local WordPress site’s directory that contains its own wp-content folder. In this case, you may rename the original folder (e.g. old-wp-content) if you got content you want to keep, so it won’t get deleted. However, you can also have it replaced 🗑 by your new folder if you’d like to. I’ve opted for the latter.

Moving wp-config.php to your localhost

Just as before, move the live site’s wp-config.php file to your local site’s directory, replacing the old one. Now, you may be tempted to leave it at that, but we still need to configure the file. If you actually try to access your site now, you will be greeted with Error establishing a database connection. 🚨 And why is that the case?

Simply, it has the wrong credentials to access your database, namely still those from your live site. That’s why it fails to connect to your database. On top of that, if you decided to give your database a different name for your local site, you will have to adjust that in your configurations too. ☝️

Alright, for this step you’ll want to open your local wp-config.php file in a text editor of your choice and change the following lines:

/** The name of the database for WordPress */
define('DB_NAME', 'chunkbytes');

/** MySQL database username */
define('DB_USER', 'admin');

/** MySQL database password */
define('DB_PASSWORD', '.........');

Make sure the right name of the database is written down, as well as the username and password of the user who has access to it (remember what I asked you to keep in mind? 😜). Once you’ve done that… we’re still not completely finished!

Changing the URLs

While we may have successfully migrated the website to a localhost, there’s still one tinsy winsy problem: our database still contains the URLs to our live website. This may cause some unexpected problems, so it’s best to change them right away! 🧐

Luckily, I’ve come across a tool from Interconnect IT that will make this easy for us. Go ahead and download it, and then unzip the file. The creators recommend to obfuscate the name of the folder by giving it a different name. In my case, I’ll rename it to chunk_sr. After you’ve done that, head over again to your local website’s directory (where wp-content and wp-config.php are located), and move the folder there.

In order to run the search and replace tool, you’ll need to navigate to it from your website. In my case, this would be the address http://chunkbytes.local/chunk_sr/. 😁 If you’re not using Local By Flywheel, your address may be something like http://localhost:8080/{website_name}/{tool_name}/. Upon accessing it, you’ll be greeted by a lovely screen.

A screenshot of the search and replace tool by interconnect/it
Interface of search and replace tool by Interconnect IT

Fortunately, the tool automatically retrieves the database credentials from the wp-config.php file, so there’s only a few things left for us to do. First of all, in the search for... field, you want to enter the full url of your live website. In my case, that’s In the replace with... field, you want to enter the full url of your local website. For me that is, http://chunkbytes.local.

In the actions, section you may then click on dry run to see it emulate the changes. This doesn’t actually replace any of the URLs yet. Instead, to have it actually make changes to your database, you’ll need to click on live run.

Et voilà! You’ve done it! Now you know how to successfully transfer a live WordPress site to your localhost! 😉

Houston, we have a problem

Don’t worry! If you’ve followed along and encountered no problems, you’re good to go. However, I encountered a peculiar problem after I migrated Chunk Bytes to my computer. Whenever I tried to access my local site, I would be redirected to my live site… 😫

Meme with Kevin Hart staring with disbelieve.
WTF is going on?! What’s this black magic?!

Keep in mind that I already had changed the URLs, so faulty links couldn’t be the problem. As it turned out, my default browser (i.e. Chrome) had cached my live site due to a plugin of mine, causing it to redirect me to it whenever I tried to access chunkbytes.local. The solution? Delete the cache or use a different browser.

Did you find what you came for? Want me to cover something else? Let me know in the comments below! Share, if you liked this post!

Published inWeb DevelopmentWordPress

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *