I’ve moved about 50 WordPress installations from various servers over the years and have found, what I consider, the “best practices”. The goal here is to transfer your WordPress website off your current host’s server and (hopefully) onto one of the Uncorrupted Servers. There are other ways of performing the migration, but I’ve found this to be the easiest. This guide assumes you have a basic understanding of terminal commands and that you can find your public_html directory on your current host’s server.
Requirements:
- Terminal (SSH) access to your new and old web servers
- An SSH client (I recommend Putty)
- A text editor for modifying the dump.sql file we’re going to create (I recommend Aptana Stuido because it performs well when opening large (20+MB) text files)
During the migration process you’ll be copying/pasting paths a lot, so open up a new text document in Aptana and paste the following into it:
Old Server Info:
Path to public_html = /replace/with/real/path/
Wordpress DB Name = replace_Me
Wordpress DB User Name = replace_MeToo
Wordpress DB Password = NewSecretPassword
New Server Info:
Path to public_html = /home//domains/example.com/public_html/
Wordpress DB Name = replace_Me
Wordpress DB User Name = replace_MeToo
Wordpress DB Password = NewSecretPassword
Now open Putty and make a connection to your old server. Once you’re logged in, cd (change directory) into the public_html directory.
Type:
pwd
Paste the output into your text file. This is the path to public_html on the old server.
Log into your control panel and create a new database, copy the DB Name, User Name, & Password and paste it into your text document.
Back to Putty… you should still be inside your old hosts public_html directory. Type these commands:
cd .. tar cvzf backup.tgz public_html mv backup.tgz public_html
So, we moved up one directory and created a gzipped tar archive of your entire public_html folder. I choose to gzip the entire folder because if you’re in the directory and pass it the * operator it will skip hidden files (like .htaccess files), which we definitely want to leave in place. We also moved the backup file into your public_html folder so we can download it from the new server.
Open up another putty window and connect to your new server. cd into your public_html directory (@ Uncorrupted it is ~/domains/example.com/public_html/)
Let’s do some cleanup:
rm -f index.html logo.jpg
Download and extract the backup file:
wget http://example.com/backup.tgz tar zxvf backup.tgz cd public_html mv * ..
So, we downloaded the backup, extracted it, moved into the folder it created (public_html) and moved all the files out. We still need to move any relevant hidden files, so:
ls -la mv .htaccess .. mv cd .. rm -rf public_html
So now you’re back inside the real public_html directory on the new host. Grab the path and add it to your text file:
pwd
Lets tell WordPress which database to use and the username/password combo needed to open it:
nano wp-config.php
Find: define(‘DB_NAME’, ‘…’); Replace … with the DB Name in your text document
Find define(‘DB_USER’, ‘…’); Replace … with the User Name in your text document
Find define(‘DB_PASSWORD’, ‘…’); Replace … with the Password in your text document
Once you’re done editing the file, press + o to save the changes and + x to exit.
Let’s go back the the other Putty window (your old host) and dump the MySQL database – replace the DB info with the DB info from your text document.
cd public_html mysqldump -u -p > dump.txt
Download the text file to your computer and open it up with Aptana. We need to replace the path info throughout the database so click on Edit -> Find/Replace
In the find block, paste your old path to public_html and in the new block paste your new path to public_html. Make sure the Wrap Search check box is checked and click Replace All. Save the text document and upload it into your public_html directory on the new server.
Import the text file into your new MySQL DB:
mysql -u -p < dump.txt
At this point, WordPress should be working. All of your posts, comments, media, etc should be working just as they were on your old host. You can test everything by editing the hosts file on your PC
Go to: C:\Windows\System32\drivers\etc and open up the hosts file with a text editor, go to the end of the file and type the IP address of your new server, press tab & type your domain name, save the document, close your web browser, and clean your DNS cache (click start, click run type ipconfig /flushdns & press enter). Next, open your browser and go to your site – everything should work. When you’re done testing, delete the lines you added to your hosts file and then save/close it.
At this point, all that’s left to do is change the DNS servers for your site and point them at the DNS servers provided by your new host. Some folks will continue to hit your old site and some will start hitting your new site. Within a couple days all your visitors will be hitting the new one. Keep in mind that it may be a while before you hit the new server too – that’s just the way DNS works. If you want to hit it instantly, check out my post about OpenDNS



this is mighty handy, thank you