Today I moved a fully developed WordPress blog from HostGator to DreamHost, these instructions should be valid for all hosts out there, by reading this you will avoid making the same mistakes I did.
Step by step guide to moving your WordPress blog
Export your MySQL database
Download your WordPress files to your desktop computer using FTP
Point your domain name DNS to the new webhost
Upload MySQL database to the new webhost
Upload your WordPress files to folder in new webhost
5 ways to export your WordPress SQL database
phpMyAdmin: Enter in phpMyAdmin, a front-end for managing a MySQL database that most hosts have installed, choose the database name you want to export, click on the export tab and then click on the Go button.
Use cPanel: If your webhost has cPanel installed (Dreamhost has not) go to Backups>Download a MySQL Database Backup.
WordPress plugin: Install a WordPress plugin called Xcloner and export your database using it, this plugin can be used to back up and restore a MySQL database.
Use SSH: Access your SSH account at Dreamhost and run: mysqldump –opt -uusername -ppassword -h yourMySQLHostname dbname > filename.sql
SQL GUI manager: There are various free and paid for software providing a front-end for the desktop to manage SQL databases, download HeidiSQL and use it to export your database to your desktop computer.
2 ways to backup your WordPress blog files
Use FTP: Use an S/FTP client like CyberDuck to connect to your hosting FTP account and download the folder contaiting your WordPress installation, this will take a few minutes.
Use your backup: If you already have an updated offline full backup of your hosting account in your desktop computer, and you should, that backup will include all of the files you need, extract them to your computer hard disk.
Change your domain name DNS settings
You will have to change the domain name DNS you want to move and use your new hosting provider name servers.
DNS propagation can take up to 48 hours to take place, during all this time your site will be down, in my case it took 2 hours for the DNS change to take effect, do not get impatient if the site does not come up straight away, you just need to wait some hours.
Import MySQL database in new host
Go to the phpMyAdmin interface to import the .sql database, when I tried it this didn’t work for me and I got a message saying “Error 1046 No database selected”.
I discovered that to import a database into phpMyAdmin you will have to create first an empty database where the old MySQL database can be imported, this empty database can have any name you like and it is the name you will enter in the new wp-config.php settings.
Use your DreamHost control panel to create a database an username, now log back into phpMyAdmin using that username and password, select the empty database you just created, click on the import tab, browse to your WordPress database backed up locally in your computer hard disk, select it and upload.
Kibibytes (KiB) explained
Notice that DreamHost phpMyAdmin import tab indicates that the size limit to import a database is 7,168KiB (varies from host to host), do not confuse KiB with Kb, KiB stands for Kibibyte not Kilobyte! 7,168KiB equals 7MB, it should be more than enough for a small site.
Kibibyte (kilo binary byte) is a new prefix for binary multiples established by the International Electrotechnical Commission (IEC), it was designed to replace the kilobyte but it’s adoption has been fairly limited.
How to edit wp-config.php WordPress file
After you have imported the database you now need to edit WordPress wp-config.php file and enter all of the new host details there, DreamHost is one of the few webhosts where you will have to change WordPress localhost setting with the specific database hostname where your database is, you can find this hostname in the control panel, in the same file, wp-config.php you will have to reflect the new database settings too i.e. username and password.
If you open wp-config.php with Notepad make sure that you do not save it as a .txt file, use Notepad drop down menu and change the default Save as type: text document to Save as type: All Files, when saving append your wp-config file with the .php file extension.
WordPress wp-config.php security tip
WordPress database settings are stored in plain text, if you have more than one blog use a different username/password for each database. To remember all those unique passwords and usernames download a password manager like KeePass.
To see your database password go to DreamHost control panel, MySQL database tab> Users with access, click on the username and you will see the password.
Another way to get hold of your forgotten database username and password is by retrieving wp-config.php from the host account using FTP and read it locally with Notepad.
The next step will be now to upload all of your WordPress files stored in your desktop computer to the new allocated folder in Dreamhost using FTP.
List of possible errors while moving a WordPress blog
When I first visited the newly migrated site on my new host I was greeted with this error:
Parse error: syntax error, unexpected T_STRING in /home/caitlin/example.org/wp-config.php on line 1
On further examination of my wp-config.php file I found that the W3 Total Cache WordPress plugin I was previously using had introduced an extra line in my wp-config.php file and due to the text lines wrongly wrapped around it triggered the error.
I proceed to to re-edit the wp-config.php file, this time using a clean wp-config-sample.php that had not been handled before and therefore could not have been corrupted by any WordPress plugin.
I visited my newly migrated WordPress blog and found a second error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/caitlin/example.org/wp-config.php on line 2
I then found out that for some reason I still don’t know when I saved WordPress wp-config.php file using Notepad the lines wrapped around, I attempted to resave it again being very careful, I still could not solve the text wrapping problem on saving the file, I finally downloaded a proper PHP editor (PSPad) to edit wp-config.php instead of using Notepad, that fixed it.
Tip: Always use wp-config-sample.php to re-edit wp-config.php and save it as a new wp-config.php file, this way you will be making sure no plugin garbage lines have been left behind in your configuration file.
I visited again my newly migrated WordPress blog and I found a third error message:
error id: “bad_httpd_conf”
The error above is specific to DreamHost, it is related to DNS propagation when adding new domains, all that it is needed to solve it is to visit Manage Domains in the control panel, look at the small DNS link under your domain name, click on it, you will be taken to a new page with a blue button that says Go!, click on it to update the DNS information, this could take some hours.
I now visited the recently migrated WordPress blog and I only found a blank page, it is important that you wait some minutes when you update your database username and password, do not be impatient like me!
If you look at your WordPress blog files with your FTP client and can not see any .htaccess file even though you uploaded it, that is probably because some webhosts do not show files with a preceding . (dot), you will need to tweak your FTP client, Dreamhost by default will not show .htaccess, more information on how to solve it here: http://wiki.dreamhost.com/Htaccess
How to access phpMyAdmin in DreamHost
To access phpMyAdmin in DreamHost enter the hostname database in your browser, for example, if you named your MySQL hostname mysql.example.com, point your browser to http://mysql.example.com and you will then be prompted for a username and password.
Managing more than one blog in a shared hosting account
If you have followed my security tip and assigned a different username to each one of your blog’s database be aware that when you log into phpMyAdmin you will only see a single database, you will need a different username/password in order to see each one of the different blog databases with only one of them being visible each time with each username.
In my old set up at HostGator I had the same username for all of my databases which made it much easier to manage because you can see all of them using a single login but this is a security risk.
The username and password you have to enter to login into phpMyAdmin is your newly added MySQL user/password that has access to that specific database, you can add more than one user but if you want strong WordPress security against multiple hacking do not reuse usernames and passwords in the database settings across blogs.
WordPress plugins to move host
The following WordPress plugins claim they can easily backup your selfhosted WordPress blog with its database and restore it to a new webhost.
Finally, if on top migrating webhost you move your WordPress blog to a new domain name, you could need to update the links in your blog posts, Velvet Blues plugin will quickly update your URLs pointing them to a new domain name or host.