How to test your website on a new server before changing nameservers

Sometimes moving to a new server is a must for a number of reasons:

  1. You need more resources because your traffic is growing bigger and your current hosting package cannot cope with the demand
  2. Your current hosting provider is not reliable, so you want to move your website to a new webhost
  3. You have changed your codebase, so you need another OS (eg if you had a site in php but have converted it to .net, you will have to move from a linux webserver to a windows one)

Once everything has been tested locally (on the development machine), you want to make sure that it’s working properly on the remote machine as well, that is, on the new webhost. What you do is to configure the DNS on the webhost for the website. Let’s call the website and deal with a linux server where you’ll get CPanel. When you sign up with the webhost, they normally ask you whether you want to host an existing website or a new one. If you chose an existing one, the DNS will already be configured for you. If you wanted to have another domain on the same account, you can use addon domain functionality in CPanel to do that. Plesk on Windows servers will allow you to create the dns zone for a new website as well.

Once you’ve added the DNS, you can edit your hosts file if you’re using Windows OS. It’s located at C:\Windows\System32\Drivers\etc and you’ll probably have to open it in Notepad with administrator’s priviledge to be able to make changes to it. All you have to do it add an entry as follows:

Replace with the IP address of your new server. You will then need to clear the cache of your browser. When you try to browse to then, you will see your website on your new server (new webhost). If there are any problems, you can fix it there and then. This allows you to properly test your website on a new webhost before actually changing your nameservers.

Once you are satisfied that the website will be working properly on the new webhost, you can then change your nameservers with your domain registrar so that your live website is pointed to the new web host. Changing the nameservers is like saying “hey, I’m not on the old server anymore, I’ve changed address, and this is my new address”.

Note that testing the website the above way is not 100% accurate because there are certain things which require the right nameservers changes before they work properly. An example is wordpress cron jobs (wp-cron.php) which did not work using this method.

comments powered by Disqus