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.
photo credit: zio Paolino
Put your site in maintenance mode
- Download and activate the ever useful Maintenance Mode plugin.
Move files and data
- Login to your current host via SSH and cd to the directory above your blog root
- Run the following command to archive your WordPress code:
tar -zcvf blog.tar.gz path/to/your/blog/
- Run the following command to dump your WordPress MySQL data:
mysqldump --opt your_database_name -u your_mysql_user -pyour_mysqlpassword > blog.sql
- 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
- Login to your new host via SSH and cd to your web root directory
- Run the following command to unarchive your WordPress code:
tar -zxvf blog.tar.gz
- 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
- Run the following command to import your MySQL data dump:
mysql -D new_database_name -u new_username -pnewpassword < blog.sql
- 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.
- Go to your domain registrar’s website and change the nameserver settings to point to your new host’s nameservers.
- 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)
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 :).