Subscribe via

A Quick Guide to Changing WordPress Hosts

In this post I will show you how to quickly migrate a WordPress blog to a different host. Certainly not everybody’s configurations are the same, so this should be used as a general guideline only.

Trasloco in corso
photo credit: zio Paolino

Put your site in maintenance mode

Move files and data

  1. Login to your current host via SSH and cd to the directory above your blog root
  2. Run the following command to archive your WordPress code:
    tar -zcvf blog.tar.gz path/to/your/blog/
  3. Run the following command to dump your WordPress MySQL data:
    mysqldump --opt your_database_name -u your_mysql_user -pyour_mysqlpassword > blog.sql
  4. Run the following command to push files onto your new server:
    scp blog.tar.gz blog.sql new_host_username@new_host_url:~/path/to/web/root
  5. Login to your new host via SSH and cd to your web root directory
  6. Run the following command to unarchive your WordPress code:
    tar -zxvf blog.tar.gz
  7. Create a new MySQL user and database on the new host. Preferably they should be the same as your current username and database name.
    echo CREATE DATABASE 'new_database_name' | mysql -u admin -padmin_password
    echo GRANT ALL ON 'new_database_name'.* TO 'new_username'@'%' IDENTIFIED BY 'new_password' | mysql -u admin -padmin_password
  8. Run the following command to import your MySQL data dump:
    mysql -D new_database_name -u new_username -pnewpassword < blog.sql

Deploying

  1. If your new MySQL username and/or database name is not the same as the current ones, you will need to update the wp-config.php file with the new login information and/or database name.
  2. Go to your domain registrar’s website and change the nameserver settings to point to your new host’s nameservers.
  3. Disable maintenance mode on the new host’s copy of your site. depending on how the nameserver settings update throughout the net, your visitor will either see a maintenance mode message (DNS pointing to the old host’s copy of yours site) or see a live site (DNS pointing to the new host’s copy of your site)

Other methods

A lot of hosts offer phpMyAdmin for you. If you do have access to phpMyAdmin, I recommend that you to substitute all MySQL steps above with the phpMyAdmin equivalent because it is easier and relatively safer to operate.

You can also skip the SSH usage and do everything via FTP and ZIP, but that’s just not as 1337 :).

2 Responses to “A Quick Guide to Changing WordPress Hosts”

[go to last comment]
  1. Cathy

    Thank you sooooo much!! This is going to save my ass!

  2. Thaya Kareeson

    @Cathy
    You're welcome! Migrating hosts can get hairy and it's always good to have some sort of check list to go through.

[go to first comment]

Leave a Reply