I do a lot of web development these days, on number of projects, which often require their own domain, so I thought I’d share a quick tip that I’ve found helpful.
In a nutshell, I use wildcard domains and used the Apache vhost alias module in order to be able to automatically create a domain per project.
Setting up bind
The first step is to set up wildcard DNS for your machine, in this case *.dev.mymachine. Assuming you’ve got bind set up, this is just a matter of configuring a local zone for your network (or adding this to your existing local zone).
It’s late, and I’m tired, Google “wildcard dns bind” and that’ll point you in the right direction.
Setting up the vhost
Next, you need to set up an Apache vhost for your wildcard domain, but crucially, instead of specifying
DocumentRoot in the normal way define
First, enable the module:
Then, set up and enable a definition which uses variables supplied by the
vhost_alias, which will use the structure of the url line to load the appropriate web page.
# Indexes + Directory Root.
DirectoryIndex index.html index.php
Options +Indexes +Includes +FollowSymlinks +ExecCGI
The above code will use the directory name plus the user’s username, for example,
What this means is that you don’t need to create a new virtual host for each one of your projects, which may save you a little time.