Tags: , , ,

Introduction

This post is about how to move a WordPress website from your computer to a live server, from start to finish, mostly manually but making quick use of one plugin along the way.

There are a lot of ways to move WP sites using different kinds of plugins. These include Duplicator, All-in-One Migration, and WP Migrate DB, to name the most popular. I don’t use any of these plugins. That’s not because I have anything against any of them. I do use a plugin for database changes, just because I find it easier–but all this will be explained in due course. This post is for those people who would like to know how to go through this process manually.

Although this may seem like a lot of material, once you master the process, you’ll be able to do the whole thing in less than five minutes (not including upload time). Like most things in life, it looks complicated at first, but it will get easier the more you do it.

This scenario assumes the following:

  • You are moving a site from a local development server (your computer) to a live server.
  • You are going to be changing the site URL.
  • You are using CPanel in your hosting account, or something very similar to it.
  • You are a beginning or early-intermediate WordPress user who is interested in getting your hands a little dirty.

Instructions:
Click each title to expand the text underneath it.

Key Terms and Tools

Site files – This refers to all the files that make up your WordPress site. They will be stored in one directory, and they include core WP files, image uploads, custom pages, child themes, and anything else that might be used on your site.

Database – Your database is a document that contains information crucial to the functioning of your site. Your site will not function without it. You will not read the database yourself, but your server will.

Tables – Tables are entries in your database.

FTP/SFTP – File Transfer Protocol or Secure File Transfer Protocol. This is a method of moving your site files from your computer to your server.

Tools mentioned

CPanel
PHPMyadmin
Sublime Text
Notepad++
Velvet Blues

Objective

To learn how to move a WordPress website from your computer to a production, or live, server.

This scenario assumes that you have already built a WP site on your computer using local development software such as MAMP or WAMP, or that you have all the site files on your machine for some other reason. If you want to know more about how to develop a WP site locally, meaning on your own computer, I’ll be doing a post on that at some point in the near future. There is also already quite a bit of information on this, if you care to search for it.

This scenario also assumes that you have already selected a provider from among the many hosting providers out there, and that you have FTP access to that account. If you don’t have a hosting account yet, you will need to get one before proceeding. There are quite a number to choose from. This article from PC Mag lists the ten best hosting providers (in their opinion). One of them should work for you.

If you don’t know how to connect to your hosting account via FTP, contact tech support at your hosting provider to ask them, or look it up on their Help section. This is a common question that they should be able to answer immediately.

1. Export your database from your local development server.

Your local development environment should offer you access to PHPMyAdmin. This is an interface that allows you to interact with your database. You would have used it when you set up the database for your local website version.

Go into PHPMyAdmin, locate your database, and click on it. (If you have many databases and aren’t sure which one goes with your site, go into your site files and look at the file called wp-config.php, which you will find in the main directory. The database name will be listed like this:

define('DB_NAME', 'database_name_here');

Whatever is in place of ‘database_name_here’ is the name of the database you’re looking for. Locate that in PHPMyAdmin and click on it.

Then, in the row of tabs along the top of the screen, click on Export.

Select the export method called ‘Custom’.

Scroll down the page until you see a section labeled Output. Select ‘Save output to a file.’ Don’t worry about the other options in this section. Just leave them alone.

Scroll down to ‘Object creation options’ and select ‘Add DROP TABLE (etc).’ Leave everything else the way it is.

Finally, scroll down to the bottom of the page and look for the little button labeled ‘Go’. It might be hard to find. Click it.

When you click that, your database will be exported from PHPMyAdmin as a file that you can move to other servers. This file will end in the ‘.sql’ extension. It will probably be exported to your Downloads folder on your computer’s hard drive, unless you have changed this default option to something else.

Note: If you checked your database name in wp-config.php, as I mentioned above, this file should have the same name. That’s because it’s the same file!

2. Locate your site files.

Your site files should be in one directory. This directory could be called anything, depending on what you or someone else named it when you set it up locally. If you are a Mac user who uses MAMP, your site files will be located in Applications -> MAMP -> htdocs. If you use WAMP, and you didn’t change the default settings, your site files will be located at C:\wamp\www\…

You don’t actually need to do anything to this directory at the moment. I just wanted to make sure you know where it is.

3. Connect to your server via FTP.

There are a variety of free FTP clients out there. I use Filezilla for moving WordPress sites.

Connecting via FTP can be confusing if you haven’t done it before. What exactly is happening here? You’re simply creating an internet connection between your computer and your live server, that’s all. You will push your site files up through this connection onto your server.

In order to connect for the first time using Filezilla, you’ll need to enter your FTP account information. You get this information from your hosting provider. If you use CPanel, it should be visible when you log in and click on FTP Accounts.

You may actually need to create the FTP account first if your host hasn’t already created it for you. Here’s a handy little .gif that should be helpful.

Once you know your FTP account info, you will enter it here:

When this information has been entered, click Connect. If your information is correct, you should then be connected.

Note: Depending on your host, you may receive a certificate warning saying that the host cannot be verified. You can just accept this warning and proceed by clicking Advanced, then Accept.

4. Upload site files

Once you are connected, you will see two windows in your FTP client. The left window shows your local directory, that is, your computer. Everything you see in that window is currently on your computer. The right side shows the server you just connected to. You can navigate through directories in either window.

On the right side:
You need to find the directory where your site files should go. Chances are you will see a folder labeled “www” or “public_html”. You can click on either of those. They will take you to the same place.

Once you’ve entered your public directory, you should see a folder labeled with the name of the website you’re uploading to. If it doesn’t exist yet, you can create it by right-clicking on the window, then selecting ‘Create Directory’. Depending on what kind of hosting setup you have, you may also need to add this domain in CPanel. That’s beyond the scope of this document, so contact your hosting provider’s support team if you need help with that.

On the left side:
You need to make sure you’re in the directory where your site files reside on your computer. If you’re using MAMP, this will likely be in /Applications/MAMP/htdocs.

Once you’re in the right place on both sides, you can simply drag the folder from your computer onto your server. The transfer process should start then. You are currently uploading your site files. Depending on the size of your site and the speed of your connect, it will usually take anywhere from five to twenty minutes. Very big sites can take longer.

WARNING: If you mistakenly upload your site files to the wrong directory on your server, your site won’t work. This is not a disaster, but it does mean you will need to do the upload again. If you do this, you should also make sure to delete the files from the erroneous location.

NOTE: It’s possible to install WordPress in various locations. Some people like to install it in sub-directories for security purposes. Others do it when they are creating a subdomain.

5. Prepare to upload your database.

In Step 1, we exported your database from your local server’s PHPMyAdmin interface to your Downloads folder. We are now going to move that database to your live server.

This actually involves a couple of steps. First, you need to ‘create’ the database on your server.

The terminology here is a little confusing, because you are not actually creating a database. You’re just creating a space for one to exist. Just how you do this may vary, but if you’re using Cpanel, you will look for a section called Databases, and you will select the icon labeled ‘MySQLDatabases’.

Here you will have the opportunity to create a new database.

Name it something that will make it obvious which site it goes with, because if you eventually have lots of databases, you will want some way to keep them organized. I usually use a combination of site name and today’s date. For example, if your site is called hamsters.com, you might want to call this database ‘hamsters_17June’. Then click Create Database.

Once you’ve created the database, you need to add a MySQL User to it. This user is just an identity that has permissions on your new database.

Scroll down to the bottom part of the MySQL Databases screen to the section called MySQL Users. Here you can either Add New User, which means creating a user, or you can Add User to Database, which means giving an existing user permission to access the database you just created. If you are adding a new user, simply enter the desired name and password and click Create User. If you intend to use an existing user, skip that step and select the desired user from the dropdown menu under Add User to Database.

From the next dropdown menu labeled ‘Database’, select the database you want to give this user permissions for. In our case, we are looking for the name of the database we just created. If you don’t see it here, you failed to create it, so go back to the beginning of this step and do it again.

Not done yet! We now need to Manage User Privileges.

Here you will decide how much authority the database user has over the database you’re connecting to. There are best practices here from a security point of view. Ideally, you should never give anyone permissions that they don’t need. However, a WordPress admin (that’s you) will eventually need all the permissions at one point or another, so just select All Privileges, and then save.

You can also read a more detailed account of how to create a database in CPanel here.

Your hosting provider should also have a PHPMyAdmin interface available to you. Locate that in your account dashboard and click on it.

6. Upload your database

Now that we’ve created space for your database to go, we will go into PHPMyAdmin on your server. Locate the name of the database you just created. We’re looking for ‘hamsters_17June’, or whatever you called it.

Click on that.

Then, along the top row of tabs, look for the tab labeled ‘Import’. Select that.

Then, we will select the database to upload. Click on Choose File.

You will need to locate the database you exported from your local PHPMyAdmin in Step 1. It’s probably in your Downloads folder. Once you locate it, simply click or double-click on it and the upload will take place. When this procedure is finished, you will have uploaded the database to its proper place on your new server.

7. Change HOME and SITEURL tables in your database.

There are two places in the database you just uploaded that need to be changed. These are the places that tell your database the address of your site. Since we’re moving from local to live, your website is going to have a different address now. Previously, it might have been called something like ‘http://localhost:8888/hamsters’, where ‘localhost’ just indicates that you were using your local server, ‘8888’ is the port on which you were connecting, and ‘hamsters’ is the name of the directory where your site files were stored. Now that your site is going live, your new address will probably be ‘http://www.hamsters.com’, or, if you prefer to get rid of the ‘www’, just ‘http://hamsters.com’.

NOTE: It is recommended to use SSL for all websites these days, which means that you will be using ‘https’ instead of ‘http’. However, you need to set up a security certificate on your server first, and that is a separate topic we won’t get into right now. Ask your hosting provider how to set up a free Let’s Encrypt security certificate for your website. SSL is important, and these days it’s free, so there’s no excuse not to have it. Once you have a security certificate set up, you can change this to ‘https’.

On the left side of your PHPMyAdmin screen, make sure you have selected your new database.

Look for a table called ‘wp_options’ and click that.

Now, at the top of your PHPMyAdmin screen, look for the tab called ‘Search’.

In the row labeled ‘option_name’, under Value, enter the phrase ‘home’ and hit Enter.

Now, in the row that appears, you will see a field called ‘option_value’. This will contain the address of your local site. You need to change this to your live site’s address: http://hamsters.com. So, just highlight the current address of ‘http://localhost:8888/hamsters’ and overwrite it with ‘http://hamsters.com’, then hit Enter.

Now we’re going to repeat the above process for another table called SITEURL. So, go back up to the ‘Search’ tab at the top of the screen, and in the ‘option_name’ field, type the word ‘siteurl’, then hit enter. You will need to replace the old site address with the new site address here as well, just like you did for ‘home’.

What you’ve just done here is tell your database the correct NEW address of your site, so that it will no longer look for things on your computer, but instead on your live server.

Almost there!

8. Connect your site files to your database.

Now that your site files are uploaded to your server, and your database is uploaded to your MySQL server on your host, you need to connect the two.

We’ll do this through wp-config.php in your site files. This file lives in what is called the ‘root directory’ of your site–that is, the very first group of files you see when you click on the folder labeled with your site name. In this directory you will see all the core WP files and directories, like wp-content, wp-admin, and wp-includes. You will also see a bunch of other single files. Wp-config.php will be among them.

You can access this file in Filezilla. Once you see it, RIGHT-click it and select ‘View/Edit’. (Don’t double-click it, or it will try to download to your computer.)

NOTE: Depending on your setup, this file will open in whatever program your computer uses to edit PHP files. I highly recommend you don’t use TextEdit, NotePad, or any other plain text editor for this, only because it can be visually very confusing to see lots of lines of code with no way to distinguish between them. There are a number of good IDEs (‘Integrated Development Environment’) out there. An IDE is basically a program you use to open files that makes them pretty to look at and easy to organize lines of code with. I use Sublime Text, which offers a free download and quite a lot of functionality. It’s definitely worth buying, but you don’t need to own it to use it here. The other IDE I have used is Notepad++ (I think this one is Windows only).

When wp-config.php opens, look for the line that says:

define(‘DB_NAME’, ‘database_name_here’);

Whatever is in place of ‘database_name_here’ needs to change. So, erase it and replace it with ‘hamsters_17June’, or whatever you called your new database. MAKE SURE YOU KEEP THE SINGLE QUOTES. Your database name needs to be exactly as it appears in PHPMyAdmin, or it won’t work.

Next, we’re going to change the database username, so look for the line that says:

define(‘DB_USER’, ‘root’);

It might say ‘root’ or it might say something else, but regardless, it’s going to be changed as well. Change this value to whatever database user has been assigned privileges on this database. You did this in Step 5.

Finally, we need to change the password for the database user. If you just created this database user in Step 5, here you will enter the password you assigned during that step. If you are using an existing database user, you will need to enter that user’s password here.

If you have forgotten the password, you have a few options:

A: You can change the database user password in CPanel. WARNING: If you do this, then any other websites using databases with that user on them will cease to function until you update those wp-config files with the new password.

B: If you have other websites that are using databases over which this user has permission, you can get the password from the wp-config.php files for those sites.

C: You can go back into PHPMyAdmin, create a new database user, assign it the proper permissions over this database, and this time record the password so you don’t forget it.

9. Visit your website's dashboard

In your web browser, go to ‘http://hamsters.com/wp-admin’.

You should be taken to the admin login screen. If you get a database error, it means you didn’t enter the correct information in Step 8. If you get a 500 error, it probably means that you either uploaded your site files to the wrong place in Step 4, or you didn’t enter the HOME and SITEURL information correctly in Step 7. Those are the two most likely things to have gone wrong at this stage.

If you successfully log in to your dashboard, let’s move on.

10. Re-save permalinks

In your dashboard, go to Appearances –> Permalinks. Scroll down to the bottom of the screen and click Save. This step is important! If you don’t do it, your menu won’t work.

11. Update links, attachments, uploads, etc. with the new address

This is the only part of the process I use a plugin for, because it just makes life easier. In your dashboard, go to Plugins –> Add New. Do a search for a plugin called Velvet Blues. This plugin will go through your whole database for you and make some necessary replacements.

Once Velvet Blues is downloaded and installed, in your Dashboard, go to Tools –> Update URLS. This will take you to the Velvet Blues admin screen.

You will need to fill out both fields as I’ve done here, obviously using your own information rather than the sample info I’m using. Make sure each address is exactly right, or this step will not work. Also make sure to select all the boxes in Step 2 EXCEPT for the last one, which I’ve left unchecked in the sample.

Click Update URLs NOW. If you get an error, you didn’t enter your information correctly. If you did, then the process should work smoothly in just a few seconds.

12. Click through your site to spot any errors.

Sometimes, depending on what theme you’re using, you might find broken images. This is because they are still looking for the image on the local server, so the information will need to be updated for that particular image if you entered its location in a field somewhere.

Otherwise, your site should be working at this point.

Common Errors

Database Connection Error
This probably means you haven’t entered your database connection information correctly in Step 8.
500 Error
This probably means you haven’t uploaded your site files to the right place, or you didn’t correctly enter HOME and SITEURL information in Step 7.
Broken images
If you hard-coded any image URLs into your local site, then those addresses will have to be changed, or the images won’t load. Some themes, such as Parabola by Cryout Creations, come with this drawback.
Pages not loading from menu
You probably forgot to save your permalinks. See Step 10.
Database won’t import
There are a couple of things that can go wrong when trying to upload your database to your host.
The most likely possibility is that you didn’t export it with the right settings. Make sure you’ve selected ‘DROP TABLE’ as outlined in Step 1. Also make sure that you are not trying to import your database into a pre-existing one. You should only be importing into a new, blank database.
Another common problem is hosts with an older version of MySQL on their cheaper shared hosting servers. I ran into this problem with Media Temple a couple of years ago after WP databases began supporting a new character type. I got an error that looked like this:

This was a bad day, because that was the day I realized that I was very quickly going to need to find a new host. The gist of the problem is this: if you see this error, your server is running an outdated version of MySQL. If you control the server, you can easily update it, but if you don’t–for example, if you’re using shared hosting–you won’t be able to do anything about upgrading. This article contains some information you might find helpful.