Migrating WordPress from one host to another in seven easy steps

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:

  1. 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:

  1. Go to your DNS hosting provider and create a new A record mapping the new subdomain to the new webhost. (aka temp.livens.org)
  2. Go to CPanel in the new host and map the new subdomain to the directory created above

File migration:

  1. 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 ./
    1. 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
    2. If you put “./wordpress/” then the resulting decompressed files will have paths like ./wordpress/wp-admin
  2. Use either SFTP or file manager to download the tar.gz file you created above
  3. 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
  4. Use file manager or CLI (tar –xzvf ./<filename>) to untar/unzip the file

Database migration and base URL update – Part 1 configure new host

  1. 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.
  2. Use the MySQL wizard in CPanel at the new host to create the new database. Be sure to:
    1. Match the database name, user and password with the one referenced in the wp-config.php
  3. 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.)
  4. define(‘WP_HOME’,’http://temp.livens.org);
  5. define(‘WP_SITEURL’,’http://temp.livens.org);

Database migration – Part 2 data migration

  1. Login to PHPMyAdmin on the old host and navigate to the database that you are looking to migrate from.
  2. Choose “export” in simple mode and click “submit.”
  3. Save the resulting “SQL” file somewhere locally
  4. Login to the new host and then open PHPMyAdmin and navigate to the database you created in part 1
  5. Choose the “Import” option in PHPMyAdmin and select the SQL file that you downloaded in step 3

Test the new site

  1. Test the new site using the temporary URL (temp.livens.org in this case) and see if there are any issues
  2. 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.)
    1. 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:

  1. 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)
  2. Go to CPanel at the new host and navigate to the “add-on domains” section
    1. 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)
    2. When creating the add-on domain be sure to point it to the folder that you created initially
  3. 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
  4. 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.

(Visited 141 times, 1 visits today)

Leave a Reply

Your email address will not be published.

* Copy This Password *

* Type Or Paste Password Here *

This site uses Akismet to reduce spam. Learn how your comment data is processed.