42foo: all the virtual hosts you need for your web development

I’ve done a fair amount of web “design” (mostly implementing designs of others) and development in the past, I usually set up a lot of virtual hosts in my local apache. I’ve done that in three different ways.

The quick&dirty hosts file

Point any of your development domains to 127.0.0.1 in the /etc/hosts file. It’s the easiest way, but you need to add them one by one. At some point, mine could look like this:

127.0.0.1 warp.dev
127.0.0.1 ebox-platform.dev
127.0.0.1 ebox-technologies.dev
127.0.0.1 jorgebernal.dev
127.0.0.1 projectA.dev
# ... and so on

Getting smart with dnsmasq

This is a more automated method. You install dnsmasq and configure 127.0.0.1 as your DNS server. Then add this to your conf:

address=/.dev/127.0.0.1

This worked well, and acted as a dns cache. But I had some trouble with dynamic dns entries at our old office: projects.warp.es would point to a local address inside the office and our remote IP from outside, so I found myself clearing the cache too often.

42foo: the zero-code web service

So I made it external. I bought 42foo.com and set up a bind zone with this:

@                       A       127.0.0.1
*                       A       127.0.0.1

So warp.42foo.com, ebox-platform.42foo.com or whateveryourprojectis.42foo.com always point to 127.0.0.1

You still have to set up the virtual host, but there is one step less for web development. Feel free to use it, and let me know if you set up something similar with a shorter domain name :)

About these ads

9 thoughts on “42foo: all the virtual hosts you need for your web development

  1. Thanks for the notes. I’ve tried to find different ways to handle this. I eventually found the /etc/hosts file easy enough to script adding/removing entries from. I have an addwebhost script that just appends the dns and copies a template vhost file into apache’s config.

  2. The problem herein lies that I, and also most people I’ve talked to about this, don’t use 127.0.0.1, but their LAN IP – so that you can have other machines and colleagues access that as well.

    Which doesn’t really make it easier, or even possible if you have dhcp with a low lease time, but still I found myself editing the hosts file too often to even start with the 127.0.0.1 approach :P

  3. Pingback: Local development – multiple vhosts - NiGhTHawK

Comments are closed.