Migrate WordPress from Localhost to Web Server

A WordPress site use virtual web server locally allows you to build and customize your website with ease and speed. Normally, developers update and test Website locally and later upload to the live environment by migrating all of their content (posts, pages, images, etc), themes, as well as plugins from a directory on their computer to their host’s production server.

I have showed you how to install WordPress locally on your Windows computer and how to get domain name and Web hosting in the previous tutorials. They are necessary and sufficient conditions for you to publish your Website. Once you want your website be availble to everyone, you can move all of your content in site to live server.
Basically speaking, there are 2 methods to migrate a WordPress site from localhost to web server.

Method 1: Using plugins for more support 

You can easily use free plugins for exporting your database, media files, plugins, and themes. You can apply unlimited find/replace operations on your database and the plugin will also fix any serialization problems that occur during find/replace operations.

There are some useful plugins that are free can quickly help you in the process of moving database. For example, you can use All in one WP migration or Duplicator. These plugins gives WordPress administrators the ability to migrate, copy or clone a site from one location to another.

Obviously, there are many handy plugins that can make this process a breeze, but in this tutorial, I’ll introduce the manual process of migrating a WordPress website from a local server to a live server because it’s helpful for you to understand how basically website work. This is the most recommended method if you’ve built everything on the local server from the ground up.

Method 2: Manually move your WordPress from Localhost to web server

As I mentioned in the How to Import/export data using built-in WordPress tools tutorial, Import/export tool will help you to move all posts, pages, media and menus to your live site. What’s about plugins, themes, widgets etc??

In this tutorial, I will show you How to move all of content and other settings from local server to live server.
Essentially, the manual process entails downloading the database file from the local installation, editing it for the correct paths before importing it to a new database on the server, and finally uploading all contents of the local WordPress installation.
Notice:

  • You have to disable the plugins that support to create cache such as WP Super Cach, W3 Total Cache and delete it. You can reinstall them after finished moving process.
  • Make sure your localhost website don’t have too much data and plugins because it will make the process prone to have more errors.
  • Make sure to save a copy of your old values, just in case anything goes wrong you can always revert back.

Let’s get stared!!!

 Step 1: Export Database File

Login your local server and navigate to phpMyAdmin (type http://localhost/phpmyadmin into the address bar).
Here is what my phpMyAdmin screen (using XAMPP)

m11

phpMyAdmin interface

All databases are listed on the left, select the database for your local WordPress site and click on Export tab at the top of the phpMyAdmin window.

m2export-tab-phpmyadmin

Export tab in phpMyAdmin

The “Quick” export method is selected by default, but you need to choose “Custom”, which will provide you with more options to export your database. Select all tables to export and gzipped for compression and click Go.

m2 export

Export in phpMyAdmin

Click on “Go” button to exported a .sql file (such as thuypham.sql) to the downloads folder on your computer .

Step 2: Uploading Website Files to live server

Open your FTP client and connect to your hosting account using your FTP connection details. You can get them from your host if you don’t have them already (the FTP logins are nomarlly the same as the cPanel details).

If you want the site to be hosted on yoursite.com, then you need to upload all files in your public_html directory (you can browse other folder at the root where you want to install your WordPress website) and copy all files from your WordPress installation folder on the local server to this directory on the live server. Now select your local WordPress files and upload them to your live server.

m3uploading

Step 3: Create New Database on Live Site

You’re done with the main part on the local server. Now you need to setup the live environment and finally get the files uploaded so that your website can go live. To setup a new database for your WordPress site, login to control panel of your web hosting and browse to MySQL Databases.
Most WordPress hosting providers offer cPanel to manage your hosting account, so we will show you how to create a database using cPanel.

m3 new sqldata

MySQL Databases.

On the next screen, create a database by entering a name for your database.m3 newdb3

Create new database

When you select MySQL Databases, you will be prompted to enter a username and password. This is the new user account that will be associated with the new database for your website. You’ll need the personal details (your username and password) when configuring the database file in WordPress.

m3 newdbuser1

Set MySQL privileges for that user

Step 4: Import WordPress Database into New Database on Live server

Now that you have a new empty database on the live server, so you need to upload your database file saved on your computer. Login to control panel of your web hosting scroll down to the databases section and browse to phpMyAdmin.

m8 localhost-to-host

Click on “Import” tab in the top menu. Browse and choose the .sql database file you gzipped and saved in step 1. Don’t care about other options, store it as defaults and click “Go” button. And you’ll quickly get the notification display that data successfully imported.
This is a crucial step because it allows you to restore exactly your website as it was on the local installation.

Step 5: Fix wp-config.php File

Due in localhost, we’ve installed WordPress website with database information different from database information on the host, so we have to fix that database information match the information on the website host can work .
Open the wp-config.php file in your code editor (browse to your local WordPress installation folder).
You need to insert informati0n as below to point url to your site :

On other side, you need to change :

  • define(‘DB_NAME’, ‘your_database_name’);
  • define(‘DB_USER’, ‘your_database_user’);
  • define(‘DB_PASSWORD’, ‘your_database_password’);
  • define(‘DB_HOST’, ‘localhost’);

Just fill in the settings you defined while creating the database on your live server in Step 2. For the host name, fill in the server IP address or leave it as localhost if your host explicitly says so.

When you’re done editing the settings, save and close the file.

Step 6: Modify Permalinks

The final step is to modify the permalink structure of your new website to match that of your old site on the local server. To do this, go to the admin dashboard of your new website and browse to Settings > Permalinks. Select the structure you used for your local installation and save. Your WordPress website should now be live.
If you have error: “Error establishing a database connection” it means that your database information is failure, so check again.

Step 7: Modify File Paths

When you are moving a WordPress site from one domain to another, or from local server to a live site, you would face that all your URLs will be absolute paths. In other words, all links to your content files (posts, images, post types) will start with http://localhost/. You have to modify this link structure for your live installation or your content will not display properly after uploading the database file.
You can either use the SQL query or use the plugin for more support ( You can use Better Search Replace plugin  or Velvet Blues WordPress plugin)
Go to phpMyAdmin, click on your database and then click on SQL from top menu. Write this query but don’t forget to change it with your own local site and live site URLs.

m1wpfiximageurls

For those who want to do it via SQL, here is SQL query that should solve this problem:

Once you’re done replacing the URLs, save and close. Don’t alter anything else.

——————–

Developing your WordPress website on localhost allows for unlimited tweaks and customizations because you can afford to make mistakes there that you cannot afford to make in a live, production environment.
I very hope this tutorial helped you to have proper insight on what happens when moving WordPress installation from a local to a live server.

Leave a Reply

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