How to transfer WordPress site from localhost to another localhost?

Many WordPress users test the plugins or themes before using them on a live website. Doing so ensures that the plugin/theme they’re planning to use on a production site is bug-free. Sometimes, these users may install another OS and would like to move the WP site from the localhost on the old OS to another localhost on the new OS or may want to move WordPress from the local to the live server.

Backup the WP directory

WP saves the photos you upload to the uploads directory in the wp-content folder. Themes and plugins can either be installed manually using the upload or install method or directly from the WP themes directory. The WP themes you upload and install or are directly installed are saved to the themes directory of the wp-content folder. Similarly, the plugins are saved to the plugins folder.

Instead of redownloading the WordPress latest zip file, you can create a zip or tar gzip archive of the entire WordPress directory. Doing so ensures two things – your media files will be moved and the themes + plugins you’ve already installed will be transferred to the new localhost. If you don’t want to create an archive of the entire WP folder, you will have to back up the WP-content folder, the plugins folder, and the themes folder.

Create a database dump

WordPress database tables

WordPress saves everything to a database. The database of WP has several tables. The content management system saves the post and page data to the WP Posts table. Similarly, the user data is saved in the user’s table, categories/tags data in the term/term_taxaonomy table, and so on. Although you can back up individual tables, we recommend you to back up the entire database using the following MySQL command:

mysqldump -u root -p db_name > backup_name.sql

In the above command, replace db_name with the name of the database, and backup_name with the file the command will generate.

Backup configuration files

In addition to the wp directory, and the database dump, you will have to move the config files of the web server and the PHP.ini file as well (if you have made some changes to the default file). If you’re using PHP-FPM, you will have to move the www.conf file as well. This file lets you configure the PHP-FPM pool, connection method, set permission for UNIX socket, etc. If you’re using the LEMP stack, you may have to modify this file. What if you don’t move the config files? If you don’t move the files, you may have to modify the default config files on the new localhost.

You’ve backed up the required files, now what?

Replace the config files of PHP, Nginx/Apache with the one you’ve backed up. Now, open the Apache/Nginx config file and note down the WP installation directory. Copy the 1st backup, the backup of the WP directory, to the path you have noted down. Now extract the files here. For example, if the config file shows this path /var/www/html/wp, copy the backup to the directory html and extract the files here. Open the wp-config file and note down the name of the WP database, user name, and password. Now, login to the DB server and create a database with the name you’ve noted down using the create database database_name command. You should also create a user using this command CREATE USER 'copied_user_name'@'localhost' IDENTIFIED BY 'password'; Now, type FLUSH PRIVILEGES command and select the database using the select database_name command. Finally, execute the statement source database_backup.sql followed by FLUSH PRIVILEGES. Restart Nginx/Apache. Congratulations! you have successfully transferred the WordPress site from one localhost to another localhost.


Pramod is the founder of wptls. He has been using WordPress for more than nine years. He builds web applications, and writes about his experiences with various WP products on this site.

Leave a Reply

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