WordPress Migration from live server to localhost

WordPress

We usually do development work in local or development environment. Then move the final product to production/live server after doing necessary changes and being sure that our application is bug free and stable. Same goes with the WordPress site development in common practice. But still we face different issues during migration process. Apart from the system and dependency issues, here we will look at the steps to migrate the WordPress site and its database localhost.

For migration process, we must have SSH or FTP access to our live WordPress site to download all the file of the site, generally available under public_html folder.

Then we need database of our live site. We can access it by logging into hosting account cPanel and export the required databases from phpMyAdmin section.

Now that we have all required files and database data, we prepare our localhost for the migration. For that, we first create database in local MySQL server via phpMyAdmin or MySQL CLI (whichever you find feasible).

After creating database, we Import the downloaded database file we exported form live server to our local database we just created. Then we run query to replace all the occurrences of live site’s URL with the local URL.

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

Then we replace localhost site’s file with the live site’s files we downloaded. And edit wp-config.php file to update database config as we created in local DB server.

Then finally, we are ready to test our WordPress site in localhost. Browse http://localhost/site in the browser to access imported site and admin dashboard we just imported.

You May Also Like