Archive for July, 2009

Local development – multiple vhosts

As with alot of devs out there, I have a couple of virtual hosts setup. It is rather annoying to keep updating the /etc/hosts file. I came across “42foo: all the virtual hosts you need for your web development” which has helped alot. But this was not enough, the virtual hosts are still static, then I found “Dynamically Configured Mass Virtual Hosting“.

So now I have the following setup:

/etc/dnsmasq.conf

no-resolv
server=<DNSSERVER>
address=/.local/<DEVSERVERIP>
no-hosts

/etc/apache2/conf.d/multi_vhost (on the devserver)

# get the server name from the Host: header
UseCanonicalName Off

# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog /var/log/apache2/vhost_access_log vcommon

# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot /var/www/%0/

<Directory /var/www/>
 AllowOverride All
 Order allow,deny
 Allow from all
</Directory>

Apache requires the mod_vhost_alias module to be loaded.

And this is it, all that is needed now is to have a symlink/directory in /var/www/ with the name of the virtualhost pointing to the document root of the dev site.

EG: /var/www/test.local -> /home/<user>/Development/test/webroot/

So now no more editing multiple files, all I need is to create a symlink and sorted :)

P.S. I did find that the Avahi daemon was causing issues see Bug #80900

To disable the Avahi daemon:

sudo invoke-rc.d avahi-daemon stop
sudo update-rc.d -f avahi-daemon remove

UPDATE: I needed to add the directory clause to multi_vhost as I needed to use .htaccess files ;)
UPDATE 2: There was also an issue with mod_rewrite (Request exceeded the limit of 10 internal redirects due to probable configuration error.) This was only happening to sites with a .htaccess. The solution was to add:

RewriteBase /

RE: Hating Microsoft

For those of you Microsoft Zealots out there read the following: Russell Coker: Hating Microsoft it might explain a few things ;)

Now STFU :p