How To Move WordPress From Localhost To Live Server

Posted by TotalDC

So you made a WordPress website on localhost and now want to make it live for everyone to see? In this article, we will be looking at how to move WordPress from localhost to live server. Let’s start!

How To Move WordPress From Localhost To Live Server?

It’s really good to build a website locally for the speedy development. Even, it saves you from unnecessary headaches of breaking your site while troubleshooting. You can safely test your site for changes and make your workflow more efficient. Once you are satisfied with the design of the website, you can transfer it to the live server. It’s easier than it sounds.

First, you need a hosting plan to upload your WordPress website. I would highly recommend Hostinger. Because it has one of the best prices and their customer support is superb.

Methods To Move WordPress From Localhost To Live Server And Publish Website

First of all, you will design and test your WordPress website on localhost. For that, you need to install WordPress and WAMP (or MAMP or XAMP, depending on your OS). For details about setting up a local environment, you can refer to my article on how to install WordPress and WAMP locally. Once you are sure about the performance of your website, you can move it to the server.

Now if you already have your domain and hosting, let’s see how to make your website live step by step.

How To Move WordPress From Localhost To Live Server

To move your WordPress site manually, you will first export it via phpMyAdmin.

Step 1: Export Local WordPress Database

To export your database, simply navigate to https://localhost/phpmyadmin/ and select your WordPress database. Next, click Export button from the top menu bar.

php my admin screen

You will find two options here – Quick and Custom. Custom will give you more options to export your database.

export tables from wordpress database

If you are choosing Custom, make sure that all the tables get selected. Choose the gzipped form of compression for the output file. The gzipped compression is mainly used for large database files.

php my admin

Under Format-specific options, select structure, and data. Also, check the following boxes:

  • Add DROP TABLE / VIEW / PROCEDURE / FUNCTION statement
  • IF NOT EXISTS
  • AUTO_INCREMENT
  • Enclose table and column names with backquotes
php my admin

Once done, click the Go button to download the database file.

Step 2: Upload WordPress Files to Live WordPress Site

To move your WordPress files, open your FTP client. For demonstration purposes, we are using the FileZilla FTP client here. First, connect to your web hosting account and browse the root directory of your live server. Then, Upload all the files in the right destination directory. For example, if you want to host the site on mysite.com, then upload all files in the public_html directory. You will get an inbuilt File Transfer feature on your CPanel if you are using a good Web Hosting like Hostinger.

upload wordpress to server

Step 3: Create a New Database on the Live WordPress Site

Your WordPress files will take a while to upload, meanwhile, import the database saved to your hard drive in the first step. Hosting providers offer different ways to do so. Some do it through phpMyAdmin & some via cPanel. The cPanel is more popular so we are creating a database via cPanel here.

First of all, log in to your cPanel dashboard. Click the MySQL Databases icon in the databases section. Top Hosting providers i.e. Hostinger. generally provide a direct link to the CPanel login in the first signup email, otherwise, you can also find it from your hosting admin.

There you have to create a database by specifying its name. After creating a database, navigate to the MySQL Users section. Here, create or add an existing user to the database. cPanel will take you to set MySQL privileges for that user. Now, grant all privileges to the user by checking every box. Then, click the Make Changes button.

Step 4: Import Local Database on Live WordPress Site

Go to your cPanel dashboard to import your WordPress database. Navigate to the database section and select phpMyAdmin. Now, you can see your newly created database in phpMyAdmin. Go to the Import page by clicking the Import Tab on the top bar menu. Next, click on the Browse button to choose the database file created in step 1.

php my admin menu

Then, press Go to import your WordPress database.

Step 5: Redirect the WordPress Site URLs

Now you have to replace all the links in the database contained inside that are still pointing to the old site location. In phpMyAdmin, look for the wp_options table in your database. Click the Browse button or the link in the sidebar to open the page with a list of fields within the wp_options table. Under the options_name file, you need to look for siteURL. Click the Edit option that will open an edit field window.

php my admin browse tables

In the input box for option_value, you can see the URL of your local install like http://localhost/test. Replace it with your new site URL in this field, for example, http://www.yoursitename.com. Save the changes by clicking the Go button.

Next, you will repeat the same steps for the option name: home. So, simply find the home tab on the wp_options page. Update the home URL to be your site URL.

Step 6: Set Up Your WordPress Live Site

Once you import the database, it’s time to configure wp-config.php. Connect to your website using an FTP client, find the wp-config.php file, and right-click to View/Edit. Look for the information:

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

Enter the database name, user, and password you created in the earlier step. After that, save the wp-config.php file and upload it back to your server. Your website should be live now so you can log in. Move to Settings » General and without changing anything, Click the Save Changes button. It will ensure that the site URL is corrected wherever needed.

Go to Settings → Permalinks, choose your preferred URL structure, and save it to ensure all post links are working well.

Step 7: Fix WordPress Images and Broken Links

Whenever you move from a local server to a live site, it is obvious to get some broken links and missing images. If you choose SQL, go to phpMyAdmin. Click on your database and press SQL from the top menu. Write this query:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'localhost/test/', 'www.yoursitename.com/');

Replace the local site and live site URLs with your own.

And that is it! You have successfully migrated your site to the live server manually.