The Linux Page

Moving a website from one server to another

Moving a website to a new server

Now and again, you have to move a website from one server to another.

There are good and bad things about that, the main problem is with dynamic websites. Why is that? Simple: a dynamic website expects to access a database and if you hit the wrong server, that will go bad.

What's the best solution?

1. Install your website on the new server, make sure it loads okay (you may want to use a test sub-domain name to make sure, although that's not a rock solid proof since some things may use a fully qualified URL)

2. Change the IP address in your nameservers (both, on the old and new servers)

3. Turn OFF the website on the old server

Why point 3? Because that way you avoid problems with people hitting the old server when now everything is on the new server.

But the IP address may be cached for 1 whole day???

Yes indeed. Your nameserver may be set to keep the IP address of your site for 86400 seconds. Some people use 43200 which is 12 hours. This is defined in the TTL. A good setup uses one TTL for the enter file making things a lot easier.

In order to avoid a long downtime, the TTL can be reduced to a minimum. Note that if you go too low, it may be considered an error and the other nameservers will eventually ignore your information and use a more sensible value (such as 86400.)

I suggest you use 3600 (i.e. 1 hour.) Although 1800 should work too (i.e. 30 minutes.)

Once you made the change in your name server, check with dig to see what the TTL now is:

   dig @ns1.m2osw.com turnwatcher.com

Note that if your TTL was 86400 before, you want to wait one whole day because any nameserver anywhere in the world may have a copy of the IP for one whole day up to your last change.

After one whole day, all the nameservers out there should have a timeout of about 1h. At that point, your switch will go wrong for some people for at most one hour... Not too much if you can make it happen at a time when you do not get too much traffic.

What if my site is not dynamic?

In that case, don't bother too much. Switch everything, but let the webserver on the old server running for a couple more days. Note that some spiders memorize your IP address for a long time ignoring your nameserver TTL value. That's okay. They are spidering the wrong site anyway!

If you have a semi-dynamic website, you may be able to turn off the dynamic part on the old server, but keep the static part. Then you will not have much problem with the transfer.

If the dynamic part requires log in or registration for modifications to happen, turn that off, and leave the rest alone. Make sure to wait until people are not in their account (i.e. 1 day as for the nameserver?) and then the transfer will work very smoothly.

With a Drupal site, you can turn it off on the old server, dump the database from the old server, restore the database on the new server, wait for 1h (or whatever your nameserver was set at) and reactivate the site. That way you avoid any disturbance. When down, you can include a message explaining what is happening.