As a service to my readers and for my own future knowledge, I wanted to explain how to move a WordPress blog from one web host to another. As I wrote previously, I recently moved to a new web host. My strategy for migration is to bring up the blog on a subdomain for testing purposes. Once I have fully tested the site at its temporary location, I use DNS to point the active URL to the new site. Let’s walk through the steps:
Create new web directory:
- Login to CPanel at the new host and create a new directory where the blog will live – my preference is to have a separate and unrelated folder for each blog for simplicity.
Configure DNS with Subdomain:
- Go to your DNS hosting provider and create a new A record mapping the new subdomain to the new webhost. (aka temp.livens.org)
- Go to CPanel in the new host and map the new subdomain to the directory created above
File migration:
-
SSH into the existing webhost and use the CLI to tar.gz the contents of directory holding the blog that will be migrating. The relevant command is : tar –cvfz <name>.tar.gz ./
- Remember that the path will match what you put in the command and so if you include “./” in the path then the resulting decompressed files will have the following path ./wp-admin.php
- If you put “./wordpress/” then the resulting decompressed files will have paths like ./wordpress/wp-admin
- Use either SFTP or file manager to download the tar.gz file you created above
- Use either SFTP to file manager to upload the tar.gz file from step 2 to the new host in the directory that you created previously
- Use file manager or CLI (tar –xzvf ./<filename>) to untar/unzip the file
Database migration and base URL update – Part 1 configure new host
- Use the file editor in new host to view the wp-config.php file on the new site focusing on the database name, database user and database password.
-
Use the MySQL wizard in CPanel at the new host to create the new database. Be sure to:
- Match the database name, user and password with the one referenced in the wp-config.php
- While editing wp-config, be sure to add the following lines. (This is used to update your blog’s URL to reflect the new subdomain.)
-
define(‘WP_HOME’,’http://temp.livens.org‘);
-
define(‘WP_SITEURL’,’http://temp.livens.org‘);
Database migration – Part 2 data migration
- Login to PHPMyAdmin on the old host and navigate to the database that you are looking to migrate from.
- Choose “export” in simple mode and click “submit.”
- Save the resulting “SQL” file somewhere locally
- Login to the new host and then open PHPMyAdmin and navigate to the database you created in part 1
- Choose the “Import” option in PHPMyAdmin and select the SQL file that you downloaded in step 3
Test the new site
- Test the new site using the temporary URL (temp.livens.org in this case) and see if there are any issues
-
I did run into a problem with inside pages showing an error. (I cannot remember the exact message, but the page was blank with only the error showing.)
- Navigate to “Settings/Permalinks” in WordPress and change the permalink settings to something else and click “Save.” Then re-select your original permalink and click save
Going live – Once you are satisfied that everything is working fine and you want the new site to go live, do the following:
- Edit the lines listed in “Database migration and base URL update – Part 1 configure new host” to reflect the active URL (e.g. www.livens.org)
-
Go to CPanel at the new host and navigate to the “add-on domains” section
- You must add the new domain to your site (let’s say it is foo.com which is different from the temporary domain, temp.livens.org)
- When creating the add-on domain be sure to point it to the folder that you created initially
- Go to the DNS provider for the base domain (foo.com, in this example) and change the records for both foo.com and www.foo.com to point to the IP address of your new host
- Wait for the changes to propagate
These instructions have served me well and I have migrated four different blogs following these steps with no downtime. Feel free to chime in with any questions in the comments section.