Random writings on running, software & product development, business and anything else

Tag: testing

Moving web servers and hosts file

For whatever reason there may come a time when you need to change web hosts for a site. Its not a good look for the world see a broken site due to differences between the old and new. So how do you test everything is set up correctly at the new host before updating nameservers?
When you type a site into the browser location bar, a DNS lookup goes on and the typed in domain name is resolved to an IP address and a known location. the requested site is returned to you. So how do you test a domain that is to be hosted at a new location? In the scenario where you do not have a dedicated IP address, the answer is the hosts file on your local PC.
Your local hosts file is checked before any DNS lookup, so adding a domain and the new IP will cause your browser to go to the new location not the old.
So what does a hosts file look like? In the case of Windows XP, something like below, ignoring the comment lines which start with a #. In this case localhost will resolve to the IP address of 127.0.1 which is your local machine.

127.0.0.1       localhost

Hosts files for other OS are much the same. Ubuntu has entries for the local machine name and IPv6 setup in its default hosts file.

127.0.0.1 localhost
127.0.1.1 mymachine.local mymachine

# The following lines are desirable for IPv6 capable hosts'
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Now if you wished to have www.mysite.com resolve to IP address 192.168.1.2 you would add the following line into the hosts file. As simple as that. It’s always a good idea to back up the existing hosts file.

192.168.1.2     mysite.com

So where is your hosts file? Obviously this varies by operating system. The table below will cover the standard location for common operating systems.

OS Location
Win XP, Vista, 7 & 2003 (32 bit) C:WINDOWSsystem32driversetchosts
Windows 64 bit C:WINDOWSSysWOW64driversetchosts
Mac OS X /private/etc/hosts
Linux distributions /etc/hosts

These lookup entries are often cached, so you will need to either restart networking or even reboot your machine for the new IP address to be used.
Once you have finished your move & testing, and updated the real nameservers for your new location, its always best to remove these temporary lines from the hosts file. That way you find the site, the same way everybody else does, and you may find out early if there are any problems.

Windows within Kubuntu with qemu

The major hassle of doing web development on Kubuntu (or any non Windows system) is the inevitable hassles with the browser which still has the majority of users (IE6). Options to deal with this include:

  • Dual booting with Windows
  • Using services such as browsershot and browsercam
  • Multiple PCs in a network with different OS
  • Let IE users be dammed

All these options have disadvantages in terms of cost and/or time. Having tried most of them, I decided now was the time to try another option – virtualisation or running an OS inside another.
In this case I have started to run Win XP with Kubuntu. Again their are a couple of options, but I went with qemu. There are a number of good resources for this on the net including:

Here are the list of instructions I used for Win XP on Kubuntu Fiesty Fawn.
em1:~$ mkdir virtual_os
em1:~$ cd virtual_os
em1:~/virtual_os$ qemu-img create winxp.img 3500M[Suggested size seems to be at least 3 Gig.]
em1:~/virtual_os$ qemu -boot d -hda winxp.img -cdrom /dev/hdc -m 256 -localtime[The /dev/hdc will be specific to your setup. /dev/cdrom did not work for me. This will start the install from CDROM, and expect the process to take time]
em1:~/virtual_os$ qemu -boot c -hda winxp.img -m 256 -localtime[Once installed this is my command to run the guest OS. The number after -m is the amount of memory to allow the guest OS. If you have plenty give it more.]
And that was it. Internet connection was working straight off. Things are a little slower but using only IE it was workable. I just need to get used to Ctrl-Alt to break out of the guest OS back to my native desktop.

Things still to do:

  1. Have the guest OS interact with the host
  2. Try Win 98 as it should be less system intensive.
  3. Have Win XP with IE7 and 98 with IE6.

© 2024 Ernie Leseberg

Theme by Anders NorenUp ↑