How to test your website before changing your domain’s nameservers
This article was posted in: Web Hosting
There are two ways to preview your website before your domain has been purchased or configured to point at our nameservers (ns1.krystal.co.uk and ns2.krystal.co.uk).
Editing your local hosts file
This is the recommended method when trying to test websites based on today's powerful and complex content management systems, such as WordPress, Drupal, Joomla etc.
This method overides your computer's DNS system by forcing it to think that a particular domain exists at a particular IP address.
For example, let's say that jimsgarage.co.uk is hosted on Krystal's hera.krystal.co.uk server. Our hera server has the IP address (at time of writing) 22.214.171.124.
BACKUP the file, C:\Windows\system32\drivers\etc\hosts and then click Start > All Programs > Accessories. Right click Notepad and select Run as Administrator. Click File > Open from Notepad, and browse to C:\Windows\system32\drivers\etc and open the file called hosts
Add the following line (replacing your own website domain)
and then save the file. You may or may not want the www. in front of the domain name. If you need both, then just add two lines, one with and one without the www.
Now, after clearing your web browser's cache (and possible Windows' cache), you should find that browsing to www.jimsgarage.co.uk will open the website on the new server.
Once you finish testing and you're ready to go live then reset your hosts file (or just comment the lines out by putting a hash # at the start of each line you added) and change the domain's nameservers to point to ours (ns1.krystal.co.uk and ns2.krystal.co.uk).
All this changing of DNS data can confuse windows, so you may need to reboot after changing your hosts file.
Note for Mac/Linux users
your hosts file can be found at /etc/hosts - to edit it on a Mac you will have to enter the command :
sudo pico /etc/hosts
This will require you to enter your admin password.
Making it easier
For the lazy among us there are some handy apps to help do all this more easily.
- For Mac users there is an application call Gas Mask.
- For Windows users there is HostsMan.
Obviously, these are third party websites, so use them entirely at your own risk!
Using CURL from the command line
If you know exactly what you expect to get from your website, and you are runing Linux or Mac, then you can run a simple CURL command
curl -H "Host: www.yourdomain.com" http://77.72.x.x/
Just change the IP address (77.72.x.x above) for the IP address of our server. This will fetch www.yourdomain.com from the server at the IP address specified. It allows you to get a rough and ready preview in text to provde your development website is delivering what it should.