Migrating Your Website To New Server Without Down Time

Migrating your site to a new server requires repointing your domain nameserver to the new server. DNS propagation needs up to 48 hours to update. So when you visit your site while your DNS server still caches your domain, you have to wait up to 48 hours to see the new server.

This downtime can be avoided by setting up your website on the new server prior to repointing your domain. But how do you do that when your new server is only accessible by IP address or server domain, because your domain still points to the old server or is still propagating?

The Domain Name System makes it possible to assign domain names to groups of Internet resources and users in a meaningful way, independent of each entity’s physical location. Because of this, World Wide Web (WWW) hyperlinks and Internet contact information can remain consistent and constant even if the current Internet routing arrangements change or the participant uses a mobile device. The Domain Name System distributes the responsibility of assigning domain names and mapping those names to IP addresses by designating authoritative name servers for each domain.

Anyway, there is a simple trick to migrating your website without downtime. You can migrate your website to a new location or server before you change or repoint your domain nameserver. The basic idea of this trick is to give your computer the exact IP address of your new server without requesting the address from the DNS server.

How to do that in Windows

  1. Open the hosts file with Notepad: Windows 95/98/Me: c:windowshosts Windows NT/2000/XP Pro: c:winntsystem32driversetchosts Windows XP Home: c:windowssystem32driversetchosts Windows Vista/7: C:WindowsSystem32driversetchosts Note: In Windows Vista or Windows 7 you need to open Notepad with administrator privileges.
  2. Add your domain at the end of the file with this template:
xxx.xxx.xxx.xxx    yourdomain.com
xxx.xxx.xxx.xxx    www.yourdomain.com

Example:

94.228.220.173    ivankristianto.com
94.228.220.173    www.ivankristianto.com

For Ubuntu or other Linux

  1. Edit /etc/hosts:
vim /etc/hosts
  1. Add your domain with the following format:
<ip> <hostname>.<domain> <alias>

Example:

94.228.220.173    ivankristianto.com
94.228.220.173    www.ivankristianto.com

For Mac OS X

  1. Edit /private/etc/hosts:
sudo nano /etc/hosts
  1. Add your domain with the following format:
xxx.xxx.xxx.xxx    yourdomain.com
xxx.xxx.xxx.xxx    www.yourdomain.com

Example:

94.228.220.173    ivankristianto.com
94.228.220.173    www.ivankristianto.com

Now when you go to your domain, it will point to your new server. Configure and test your website on the new server. Don’t forget to configure your email account and email forwarding if any. After you think it’s okay to go live, update your nameserver and leave it for a while until it fully propagates. To test your website from all over the world you can use host-tracker to see if your domain has propagated to the new server.

That’s it for now. If you have more tips and tricks, please leave a comment below. Thanks.