Website migration is something most people from time to time. Folks switch hosts because of many reasons, from poor performance to cost and lack of support. You have migrated WordPress blogs to a different host?
Yes. I have migrated my WordPress blogs many times to many different host providers. I switched in the past because of cost, poor support and seeking better deals with new hosts.
In the past few days, I migrated three WordPress blogs that were hosted at three separate host providers with three separate bills. I migrated all three blogs to a single host. Doing this saved me a lot of money.
The day you decide to migrate your blogs or websites to a different host, follow the steps below to make the process as easy as possible and avoid all the pitfalls that I went through.
Step 1: Backup your site content and database
The first step prior to migrating or switching host providers is to backup your current WordPress content as well as its databases. Depending on the size of your content, this may take a while.
Below is the command I used to backup my WordPress content on a Ubuntu server.
tar -cvpzf backup_content.tar.gz /var/www/html
Because of the way I ran my WordPress blogs which wasn’t the smartest way, I put WordPress content in the default Apache2 root directory, which is /var/www/html on Ubuntu servers.
The command above backs up the entire /var/www/html content and store it in a file called backup_content.tar.gz in the directory you’re working from.
Next, backup your WordPress databases. Since most WordPress installations store content either on MySQL or MariaDB servers, the commands below can be used to backup WordPress databases from those servers.
mysql -u root -p wpdatabase > wpdatabase.sql
Replace wpdatabase with the actual database name on the server. This will create a backup of the database and store it in the whatever-name.sql file in the current working directory.
After backing up your data, you can then copy it to the new host.
Step 2: Copying and Restoring the Backup
I used SSH secure copy to copy the backed-data to the remote host. The commands show you how.
scp backup_content.tar.gz firstname.lastname@example.org:/root/ scp wpdatabase.sql email@example.com:/root/
The above commands copy both data to the new host via SSH. Replace the IP address with the remote server IP address. You should already have SSH server installed on the remote host for this to work.
When data data have successfully copied over to the new host, logon to the new host and extract or restore the content. That can be done using the commands below.
sudo tar -xvpzf backup_content.tar.gz -C /var/www/html/example.com
Make sure to restore the content to the root directory of your site. Verify the directory and folder permission as well. Next, create a new database on the database server. Then restore and backed-up database content in it.
Create a New MySQL / MariaDB Database
Your final task is to create a new database to restore the backed-up database content into. To do that, run the commands below to logon to the server.
mysql -u root -p
Then create a new database, maybe with the same name, by running the commands below
CREATE DATABASE wpdatabase;
Exit and go back to the terminal and restore the database content into the newly created database by running the commands below.
mysql -u root -p wpdtabase < wpdatabase.sql
The user account for WordPress to use to connect to the database should also be created and given full rights to the database. To create a WordPress user, logon back onto the database server and run the sql statement below:
TE USER wpuser@localhoat;
Then set the password for the user
SET PASSWORD FOR 'wpuser'@'localhost' = PASSWORD('new_password_here');
Now save your settings and exit.
Step 3: Finally Verify all settings match the previous host
Now all that’s left is to verify the folder permissions of the new host root directory match that of the old settings, make sure wp-config.php file has the correct database connection information and restart Apache2. Hopefully, your site will come up on the new host.
This is the basic process of migrating your WordPress blog to a new host.