Migrating a WordPress Website to a New Host
Using a test server to develop your WordPress website is the best way to make changes to a site. There are a few important advantages doing things this way instead of on a live site. Once you have tested everything on your local machine or remote server, then and only then should you publish your site to a live domain.
This post is part 3 in a 3 part series on creating a local test server. Previously we showed you how to install WordPress locally with XAMPP and how to copy your live site to a localhost on your machine
After you have created a test server by installing your site locally and you have copied your live site to your localhost — the next step is to move your test site back to your live host. This post will show you how to migrate your site to a live host. This means you are moving your database and site files (themes, plugins, posts, WordPress core etc.).
This tutorial shows you how to migrate your site manually via ftp/ sftp and phpMyAdmin. Most web hosting services have a way for you to access. You can use plugins to help you do this, but we are doing it manually to help show you how the process works. You can use this same method shown here to move from one domain to the other as well. You don’t have to be too technically saavy to do this, just follow along. This walk-through shows you how to migrate your WordPress website in 7 easy steps.
- Upload your site files to the live host
- Export the test site’s database from
- Create a MySQL database for your live site
- Import the database tables
- Change the site URL
- Edit the wp_config.php file
- Update all the links on your site
Before you get started
To follow along you will need a few things. First you need to have a localhost with WordPress installed and full access to it. Almost all hosts will give you access to your site files, as well as access to the database. You also need web hosting that is compatible with WordPress. See requirements to run WordPress for more info. The last thing you need is access to your web server through FTP or shell.
*Important – this goes without saying but you will want to backup everything and save it in a safe location in case something goes wrong and you have to start from scratch.
The whole process shouldn’t take too long. The longest step includes copying your site files to the new server via FTP. If your host has a file management system giving you access to the site files then you can use that as well. Below are a list of the tools you can use:
FileZilla ftp client
A text editor – Notepad++
A web browser
Step 1 — Upload site files to live site via FTP
First off we will need to upload all your files to the site. We can do this first since it takes the longest. While we are waiting for the files to upload we can get started with the other steps. For this step you may be using SFTP. Connect to your host and upload all your website files.
Step 2 — Export local database
While your files are uploading you can export the database tables from your test server. Open XAMPP and start Apache and MySQL.
Navigate to your phpMyAdmin. In my case it’s localhost/phpmyadminFind the database you want to export and click on the export tab. You will need it I a moment.
Click go.
Step 3 — Create MySQL database on live site
Now that you have your database tables, you will need to create a database to put it in on your live site. I can do this from the cPanel when I log into my hosting account. First I will go to MySQL databases.
Hit the create database button.
Next I will need to create a user and give them access to the database. After the new user is created, I can go ahead and add a user to the database.
Grant all privilages to the user.
Step 4 — Import the database
The next step is to import your database to the live site. To do this you will need your username and password that you created in the previous step. Navigate to the phpMyadmin login page through the cPanel. If you are having trouble accessing your phpMyadmin url see this WordPress Codex article.
Enter your username and password for the database you just created.
Click on your database and select the import tab.
Step 5 — Change the site URL
Now that you have everything in place it’s time to configure the database so it matches your new domain. You can do this with a SQL query. Your code may be slightly different here than mine. I changed my prefix to adamwp_. The default prefix is simply wp_. You can copy the following code and hit the Go button:
UPDATE adamwp_options SET option_value = replace(option_value, 'http://localhost/wordpress', 'http://all-written.com') WHERE option_name = 'home' OR option_name = 'siteurl';
Step 6 — Edit the wp_config
Now we need to edit the wp_config.php file to make it point to the right database. If you don’t the database won’t be connected to your site. Open the file in a text editor and change the highlighted areas.
Next upload the updated wp_config.php to your site via FTP
Step 7 — Update paths
The site will work at this point but you need to change a few things like the internal link structure. We will run an SQL query once again as shown below.
Now visit your live site and everything should be in order.
Now check the links.
Congratulations! That’s all there is to it. This is a great method for developing your site offline. Hopefully everything worked out according to plan. Checkout your site and make sure all the plugins are working as they should. If you are doing this on a regular basis you can use plugins to make things easier. For backing your site files and database checkout Duplicator. The free version has everything you need. Search and Replace is also another free plugin that helps you modify your database. Let us know in the comments section if you have any problems and I’d be more than happy to help you troubleshoot them.
Leave a Reply
Want to join the discussion? Feel free to contribute!