How to Move WordPress Localhost Site to Live Server?

In our previous articles we have described how to install WordPress on localhost using MAMP and how to move live WordPress site to localhost. When you start building a site, it may also necessary to build a site on localhost and then move the content to a live server after everything works fine. Sometimes you may also do periodic testing and development on localhost site and then move the changes to the live server. At any case it makes a good sense to understand how to move WordPress localhost site to live server so that you can use your local copy to restore the content on emergency.

If you are using SiteGround, you can use the staging function to create a copy of your local site on the server.

Move WordPress Localhost Site to Live Server

Below is the summary of steps involved in this process:

  1. Use FTP and upload all the localhost files to your live server’s root.
  2. Export local database using phpMyAdmin of local server.
  3. Create a new database on your live server using phpMyAdmin option.
  4. Import the local database tables to live database using phpMyAdmin option on live server.
  5. Replace all occurrences of localhost links to live site’s links.
  6. Verify and modify the database name and password in wp-config.php file.
  7. Login to your live WordPress admin dashboard and check the content.

Step 1 – Upload Localhost Files to Live Server

Launch your FTP client and upload the localhost files to a live server. Generally the content can be uploaded under the root “/public_html”. If you want to install WordPress on subdirectory then create the folder and then upload the content inside the folder.

FileZilla Screen Options
FTP Using FileZilla

If you want to install it on a subdomain then create a subdomain from your hosting account and then upload the files under that subdomain folder using FTP. Learn more on using FileZilla for FTP.

Note: If you have MAMP local installation on Mac then the content will be available under “Applications > MAMP > htdocs”.

Step 2 – Exporting Localhost Database

Launch your localhost server and then navigate to “http://localhost/phpmyadmin/” URL on the browser address bar. Click on the export button and download the database in a compressed “zipped” or “gzipped” SQL format.

Download Localhost Database
Download Localhost Database

Step 3 – Creating New Database on Live Server

Login to your live hosting account and navigate to “MySQL Databases” section. Create a new database with the same name as your localhost database. Add a new user and add the database to the user. Learn more on creating a database in Bluehost hosting account.

Create a New User for Database
Create a New User for Database

Remember the username, password and database name which need to be used in step 6.

Note: You can also create a database under phpMyAdmin but username, password and assignment to be done from MySQL Databases section of cPanel hosting account.

Step 4 – Importing Local Database to Live Database

Once the live database is created, again go back to “Import” tab under phpMyAdmin section and upload the local database from step 2 to your live server.

Import Local Database to Live Database
Import Local Database to Live Server

Step 5 – Replacing the Links

Now that you have uploaded the local site files and local database to your live server. But when you create local site the URL will be starting with “http://localhost” hence you need to replace all the occurrences of the localhost URL with your live site URL.

Under phpMyAdmin section of your live server, go to “SQL” tab and run the below query.

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

This query will replace all localhost URL with your site URL. We have used HTTPS for the live site, however you need to use HTTP for localhost.

Step 6 – Modifying wp-config.php File

If you try to open your live site, you will probably see an error message “Error establishing database connection”. The reason could be that the database username and password are not correct. Generally the database name and password on localhost are same as “root” but you might have created a different name in step 3.

Locate the file “wp-config.php” under the root of your live server installation. Open the file on editor and provide the correct username and password against “DB_USER” and “DB_PASSWORD”. Also ensure the “DB_NAME” is the name of your database you have created in step 3. Save and close the “wp-config.php” file. Check out separate article on editing wp-config.php file.

Modify wp-config php File
Modify wp-config php File

Now that you have a database, username and password which are correctly configured in WordPress configuration file.

Warning: If you change the database name in wp-config.php file, ensure to rename the database under “Operations” tab of phpMyAdmin.

Step 7 – Verify Live Site Content

Login to your WordPress admin dashboard with the URL “http://yoursitename.com/wp-admin/” using the same username and password details of your localhost. This is NOT your database username and password as you created in previous step 6, it is the username and password of your WordPress installation you might have chosen during localhost installation.

You will be able to see all the posts and media files as you created on your localhost.

Conclusion

We strongly recommend you to keep a local copy of your live site. This will help you to move the content to live server when required. Also, you can do the updates and testing on the localhost and then deploy in production server without facing problems. Alternatively, you can create a staging site to clone your live site on the server. In this way, you can keep a copy on the server to test and push changed to live site quickly.

Editorial Staff at WebNots are team members who love to build websites and share the learning with webmasters community. Follow us on Facebook and Twitter.

Leave a Comment