When I moved my site from my shared host to my shiny new VPS at Linode, this was a concern for me, particularly as I had a continually changing database.
Scouring the web, I found some scant instructions but nothing thorough, and no tutorials that gave me confidence. So I asked at the Linode forum, and the process mapped out below is a recap of the advice given by the kind folks there, along with my own experience.
.. So, for this process, you can thank Linode forum users btmorex, Lykaon, kirbysdl and hybinet (hats off to you chaps!)
This guide refers to a shared-to-VPS move, but can be applied to any server-to-server move.
First up, Self-Service
DON’T TELL YOUR OLD HOST THAT YOU INTEND TO MOVE AWAY.
Most won’t much care but I’ve encountered some weirdos in my time.
Sign up with a New Web Host
If you’re not sure what type of host you need, VPS (Virtual Private Server) vs Shared vs Dedicated will help you choose.
If you’re going the unmanaged VPS route, read Setup Unmanaged VPS: The Ubuntu-Nginx Guide from top to toe. If you are unmanaged, for the rest of this tutorial, I’ll assume you’ve built your box. For shared, managed VPS or dedicated, your box is built anyhow, so let’s skip on.
Create DNS Records
Basically, these tell a server to look for a domain.
If your new host doesn’t allow DNS configuration, that’s pretty poor. Else you’re with a shared server, in which case you get what you pay for. For those who can perform DNS administration ..
Add DNS records in your control panel so, for example, with Linode or Slicehost that’s done in the DNS Manager. You can refer to Add a Domain Zone to Your VPS for details and an explanatory video. Give everything a really low TTL (time to live) value. If you have any MX or other DNS records with your current host, replicate those.
Don’t worry, this doesn’t make your domain resolve to the new host prematurely, but does prepare it for the migration.
Twin the Old Site or Blog
Duplicate your site or blog’s file structure on the new server, create & link any databases and import your data within.
Amend Hosts File to Test Site or Blog
Top trick, this. You can alter the hosts file on your PC to redirect your URI to the new server, just for you. This doesn’t effect the original site at all so don’t worry about that.
Open the hosts file like this:-
Goto my c: > windows > system32 > drivers > etc and open hosts with a text editor.
You’ll know it’s the correct file because it’ll have an entry or two like:-
… and that is the format you want for the new lines you have to add to the file. So add something like:-
… swapping the IP for your new IP, and the domain for yours.
Upon saving the file, when you surf to domain.com, instead of taking you to your old server, it will take you to the new one, and you can fully test your site’s functionality.
(I told you that was top )
NOW TEST YOUR NEW SITE’S FUNCTIONALITY.
But don’t administer the wrong site: after testing, don’t forget to delete the new hosts entry, else comment it out with a # at the beginning of the line. And restart your web browser.
Move your email accounts from your current host.
If you want a simple, spam-free solution with no web server resource cost (ie no personal mail server), check out the Google Apps for Domain-Specific Email.
Test your email.
Create A or AAAA Records
This is the key to a seamless move, which is particularly important if, for example, you host a forum or receive a lot of blog comments.
What we’re going to do is to set up your new host to resolve the domain call to your old host. Basically, this eliminates the possibility of writing to more than one database while, for example, the nameservers propagate or Google’s global servers refresh your new domain details.
In the new server’s DNS settings, add two A/AAAA records using these guidelines:-
|Hostname||IP||TTL (Time to Live)|
|domain.com||old web host IP address||shortest option|
|www.domain.com||old web host IP address||shortest option|
When you save your options, you may find one of the hostname fields is blank. That’s normal.
Point Domain to Nameservers
Goto your domain registrar account and look for the Nameserver option. Renew the data.
For example, with Linode, bless, change to ns1.linode.com, ns2.linode.com, ns3.linode.com and ns4.linode.com. You’ll find your new web host’s nameserver details easily enough.
Now we are awaiting full propagation, at all server points around the world. I have no idea how long that takes, but about 72 hours is generally reckoned, so allow for 4-5 days to be safe.
Go back to those A Records we created, replacing the old host IP to your new host IP. Set the TTL to the shortest possible ‘time to live’. But before you click OK ..
Take a final backup of your old database and import the data into your new one.
.. And now you can click OK on those new A records.
While your A record changes will update the new host nameservers within minutes, it takes up to 72 hours for full web-wide propagation. You may find new data records in the old database, so you’ll have to export and import those strays.
Note: At Linode, updated DNS records take effect every 15 minutes. So if you edit an A record at 2:32, it’ll take until 2:45, plus the time period specified in the TTL, for the update to be visible to the world. Careful timing will give you the least downtime.
If you completed the previous testing properly, there should be no surprises. Then again ..
After the time period specified in the TTL, check your site to ensure everything works. Because your local nameservers may not yet have resolved with the new A record data, and so that you can be sure you’re looking at the new, not the old, web application, use the host file trick.
Shed Shared, Viva Virtual!
Whatever kind of web host you’ve moved to, you can cancel the old host 4-5 days after moving day. Your breathing will gradually shallow out.