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.
Move WordPress Localhost Site to Live Server
Below is the summary of the steps involved in this process:
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.
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.
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.
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.
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.
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', 'http://www.yoursitename.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, ' http://localhost ', ' http://www.yoursitename.com ');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://localhost',' http://www.yoursitename.com ');
This query will replace all localhost URL with your site URL.
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.
Now that you have a database, username and password which are correctly configured in WordPress configuration file.
Note: 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.
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.