Well folks its time that my old home hosted server is retired. Which means I have to migrate all of my 5 websites to a new server. Thanks to the way apache, MySQL WordPress and Drupal work, its easy.
# ssh username@oldserver # scp /etc/apache2/sites-available/ user@newserver:/etc/apache2/sites-available/
This will copy all the apache config files over to the new server. Now enable all the sites you copied by creating a symbolic link for each .config file you copied in sites-enabled.
# ln -s /etc/apache2/sites-available/yourwebsite.com.conf /etc/apache2/sites-enabled/yourwebsite.com.conf
or use the command a2ensite which does the same thing for you
# a2ensite yourwebsite.com
Restart apache for the changes to take effect.
# /etc/init.d/apache2 restart
# scp -r /var/www/ username@newserver:/var/www
Default WordPress and Drupal installs are just files and we have now copied them across. However all the content, comments etc are stored within MySQL so lets migrate that now.
Start by being logged into the old server.
# mysqldump --all-databases -u root -p > backup.sql # scp backup.sql username@newserver:/home/username/ # ssh username@newserver # mysql -u root -p < backup.sql
What we did here was use mysqldump to script every database and its contents into several sql commands. Then we copied them to the new server and piped them into the new sql server. All our databases, users and table contents have been imported. Magic.
Now all you need to do is reconfigure your DNS servers to point to the new IP address. Chances are your not hosting your own DNS server so you will have to update them using your provider's web interface. A word of advice though, create a new entry like test.yourdomain.com and point it to the new server first to make sure everything works.