Setting Up Domains on Your Computer For Development Work
February 2, 2010 by David · Leave a Comment
I, like most people who like to test out new website applications/scripts or do some personal dev work, have a webserver installed on my computer. A grumbling I’ve heard often (most recently was last night, at the time of writing) is that they always have to have the script in a subdirectory, eg localhost/blahblah. Sure, they say, you can have your own domains, but only if you set up a DNS server. Which they don’t want to maintain.
Uh…. no you don’t. Just use your hosts file. How do you think your computer knows how to resolve localhost anyway? This little file is often overlooked, which is a shame. Just slap the domains in there and you’ll be able to host multiple sites on your computer (obviously you’ll need to configure the webserver to handle the domains). On Linux, the file is usually /etc/hosts, on Windows it’s C:\windows\system32\drivers\etc\hosts and on the Mac (Mac OS 10.2 and later) it’s /private/etc/hosts. They all follow the same format ([ip address] [domain name], eg 127.0.0.1 localhost).
Once edited, the domain will start resolving immediately. Trust me, it’ll work. Yeah, DNS is more feature-full, etc, etc, however for purely internal use the humble hosts file is still the best way to do things.