How to move live WordPress site to local server in 4 steps [Tutorial]

Learn how to move WordPress site to localhost for free in this tutorial. You can use the same process in reverse to move WP site from localhost to server, or from one domain to another.

We’ll use a free plugin that also handles serialization problems. The tutorial is written so even a WP beginner can follow along and get the dev version running on the local machine in no time.

Prerequisites:

  • basic understanding of how WP works
  • experience with FTP client
  • experience with phpMyAdmin interface

While I did try to write this tutorial so it’s easy even for a novice WP user, you still need to have some understanding of how WP works and experience with FTP client.

If you are looking for an even easier way to migrate WP (to localhost or a different domain) you should check out the Updraft Migrator.

It is “The World’s Simplest Way to Migrate a WP Site”. It is a part of the UpdraftPremium plugin but it is also available as an Add-On starting from just $37.50. Well worth it in time saved and nerves spared. Check out this in-depth guide on moving WordPress via Updraft Migrator.

Part 1: Export the WordPress database

Let’s start by exporting the DB of your live site. If you are familiar with phpMyAdmin, chances are you already know how to export the DB. However, due to the serialization problem that is not the recommended method.

WordPress serialization problems while migrating the site

WordPress has serialized data inside its database, which can have a negative effect on data portability, in our case while migrating the site.

This is how the serialized data typically look like in the database.

a:2:{i:0;s:26:"http://some-old-domain.com";i:1;s:0:"";}

Data serialization is used in order to improve performance or efficiency in a database. By using data serialization, all of the (e.g. plugin-specific) data can be used in an array in just one field. This leads to saved space and simplified SQL statements. Serialized data is stored and recovered using PHP’s serialize() and unserialize() functions.

However, the problem is that you can’t run a MySQL query on serialized data. Also, when migrating the site, people tend to use search and replace functionality in a code editor which doesn’t work.

So based on the snippet above, if you just change the domain name from:

http://some-old-domain.com

to:

http://new-domain.com

character count (s:26) doesn’t match what follows anymore! And that invalidates the row.

So for example, if your theme options stored a full URL path for some settings or an image, it may end up showing default theme settings on the site instead of your custom settings.

If you are performing a basic SQL search/replace on your site, it won’t be able to update these rows containing serialized data, because it won’t automatically update the character count.

However, searching and replacing the database using PHP does not break the serialized rows and that is what a proposed plugin does for you automatically.

Avoid WP serialization problem with Search and replace plugin

Step 1: Install and activate Search and replace plugin by Inpsyde Gmbh

Search and replace plugin

Step 2: Navigate to Tools/Search and replace

Search and replace dashboard


Step 3: Click on the “Search & Replace” tab

Step 4: Enter the “Search for” string. This is where you enter your site’s URL. In my example, it was -> https://fantasy-sports-info.com

Step 5: Enter the “Replace with” string. This is where you enter the new URL. In my example, it was local dev URL -> http://localhost/fsi

Step 6: Select all tables

Step 7: Unselect Dry run

Step 8: Choose “Export SQL file with changes” Important! Please make sure you have this value selected, otherwise, you will make changes on the live site

Step 9: Click “Do Search and Replace” button and if you did everything right, you should see the message like the one below

Status report search and replace


Step 10: Download SQL file

Migrating DB using this plugin is not only easy, but it also takes care of the serialization problem.

Part 2: Import DB to localhost

This second part assumes you know how to access phpMyAdmin on your localhost. You need to navigate to it and create the new DB. Select it and then import the SQL file we generated in Part 1 of this tutorial.

Import DB via phpMyAdmin

First make sure you zip the SQL file and rename it in a way that it ends with .sql.zip.

If your zipped SQL file exceeds the default max allowed file size of 2048KiB, you can either change that default max allowed size within your local php.ini file, or better yet, import the DB by executing the command:

mysql -u username -p database_name < file.sql

For more details check out this stack overflow answer.

Part 3: Download files via FTP

Now when we successfully exported DB in Part 1 of this tutorial and then imported in the local environment within Part 2, it is time to download theme, plugins, media and other WP files via FTP from the live site.

If you are using XAMPP, you would want to create a folder for your local site within htdocs and store everything there so it is accessible within your browser at http://localhost/your-local-folder

For this task, I recommend using FileZilla FTP client. This part assumes you have FTP access and know hot to use an FTP client, but if that is not the case, you can follow this awesome wpmudev tutorial.

Part 4: Connect DB

Finally, when we have our local DB set up and folder within htdocs containing all of the WP files and do, we need to connect DB. We do that by editing the wp-config.php file

Open it up and navigate to the part of the code that reads:

// ** MySQL settings - You can get this info from your web host ** //

You want to enter your localhost DB information on the lines below


/** The name of the database for WordPress */
define('DB_NAME', 'your-DB-name');
/** MySQL database username */
define('DB_USER', 'your-DB-username');
/** MySQL database password */
define('DB_PASSWORD', 'your-DB-password');

Conclusion

Congratulations – if you did everything right, following the 4 easy steps above, you have managed to successfully transfer your live WordPress site to localhost environment for testing and developing new features. It is always a good idea to do that when you are planning on doing some face-lifting.

But if your site is not reachable on localhost, if you are getting some errors, the usual suspect could be the .htaccess file. I had that problem once. The thing is, there are plugins out there that can modify your .htaccess file which could cause problems after migration to new domain/localhost.

This is an easy fix, you can try to replace that .htaccess file with default WP .htaccess file. Just make sure you keep the old .htaccess file somewhere else as a backup.

Hope you enjoyed this tutorial and you found it helpful, if you did, please share on social media 🙂

If you have further questions, please comment below. But if you are lost and can’t follow, consider buying Updraft Migrator – “The World’s Simplest Way to Migrate a WP Site”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.