This article is an answer to a question I got recently, which stated:
When you transfer your site from old domain or localhost to new domain, what are the steps to take and what errors do you need to look for?
While this question is about transferring a domain it also applies to changing hosts. Coincidentally, I did that very thing this week. So to do this we are going to need to do 3 things:
- Backup the Files.
- Backup the Database.
- Point the domain to the proper IP address.
- Import the Files.
- Import the Database.
A quick note before I explain the procedures. The order of these things matters, not so much on the backup but on the import it can matter a bunch as you will see below.
The files in WordPress are of 2 types, there is WordPress core files which drives the WordPress system. We are not interested in those. Core files are located in the root of the install. The user files are stored in a directory called wp-content.
Depending upon the setup you have you may see a variety of directories within this one. However, there are 3 directories that we are interested in:
- Themes stores your theme files.
- Plugins stores your plugin files.
- Uploads stores your media files and documents.
I recommend that you make a copy of wp-content so you have everything you need. If you are on a local install, called localhost or 127.0.0.1 (localhost IP address) you already have these on your system. Just navigate to the folder that contains you WordPress installation.
If you are on a host and you are moving to another one, use your FTP client to navigate to the wp-content folder and download everything to your computer. Once you have done this you can more on to the next step, backup the database.
Backing up the database on WordPress is interesting because there are 2 ways to do this. One is far easier for the average user but it isn’t quite is thorough. The second is more thorough but it is harder and requires more technical knowledge. I am going to show you both methods and you pick which one you want to use.
The easy way uses functionality built into WordPress. This is the recommended way for most users. To access this functionality on the WordPress Dashboard -> Tools -> Export. The system will then ask you what to export and you want to click all content (this should be selected by default). This will download an xml file with all your content. Check your downloads folder and you will see it.
Hard (More Thorough) Way
If you want to do it the harder but more thorough way, then you will backup the entire database. The step we just did above only gave us the content, which is themes, plugins, posts, pages and media files. The database stores more than the content. It still stores all the content but it gives us the full system settings as well.
To backup the database go find PHPMyAdmin in your local server or your host’s cPanel. Once in there select the database you want and click the export button. In the dialog that appears select quick under export method and the dropdown should be SQL. Click Go and the file will download. You have just exported the full database.
Point the Domain To Your Host
Now you need to go point to the domain to your hosting provider via DNS. The DNS translates human readable domains like google.com to an IP address like 184.108.40.206. You are going to need to create an A record with your registrar.
Please note it is very common for your host to also be the registrar but this is not always the case. If your registrar and your host are different companies you need to login to your account with your registrar to point them to the host. However, you will need to first get the IP address from your host.
Once you have your host’s IP address login to your register and go to the DNS section for the domain you want to point. You are going to add 2 A records with the following values:
Depending upon your registrar’s system the TTL (Time to Live) value may be in minutes or seconds. Just select the shortest option.
Import The Files
Remember earlier I said the order mattered, well now I will explain. I want to you move the files first because the media library will not find the files (and thus will not add them) if you import the data before the files. So I recommend moving the files first. Please note you will need a WordPress install (or at least the file structure) up and running before you can move the files, which I discuss here.
Once the WordPress install is created and your FTP is setup with your host navigate into the wp-content directory both locally and on your host. Move the Themes, Plugins, and Uploads directories from you computer to the host.
Import The Database
Just like above there is an easy way, good for most users, and the harder more thorough way. I will explain each method.
The easy way will use a feature of WordPress called the WordPress Importer. On the WordPress Dashboard go to Tools->Import. There you will see a bunch of options. At the end of the list is the WordPress importer. Click install and then run the tool. When you run it will ask for the export xml file we dowloaded earlier. This should import all the system data. When you import you may need to reassign content to a user.
Hard (More Thorough) Way
Before you import the database you need to get a fresh install. Using this method you will need to do it manually. Go to WordPress.org and download the files. Extracted the files from the zip and FTP them to your root directory on your host. Now you can move the database.
On your hosts cPanel go to the databases section. Create the exact same name as the database from your localhost or other host. Then go to your new host’s PHPMyAdmin and find the database you created and select it. It should not have tables. Click the import button and import your SQL file. Then install WordPress manually using that database as the database and the same table prefix as the prefix used in the database you are moving.
Moving a WordPress website doesn’t always go smoothly. Below is a list of the most common issues I have run into and how to solve them:
- Issues with the domain: DNS can take up to 72 hour to take effect across the internet. This is why we set the TTL to the lowest value possible. You may need to be patient. Also confirm that your records are pointing to the correct IP address that you got from your host.
- Cannot install WordPress: This is more common in manual installations. Ensure that your database name is correct and that all the usernames and passwords match. Also ensure that your table prefixes match the previous version as well. If necessary delete all WordPress files get a fresh download and start over.
- Settings are not correct: This happens when you use the WordPress Importer since it only affects content, not settings. Active your theme and plugins. Re-create your menu and configure your WordPress settings.
So now you should know how to move a WordPress website from a localhost or from one hosting company to another. Also you particular host may have migration tools available, so check with them.
There is more to it than this, things like security, SEO, and domain email but this tutorial will get your WordPress website to the right location.