HOW-TO: Virtual Document Root on XAMPP for MacOSX version 1.7.3
If you develop locally, like I do, chances are you need multiple virtual hosts running on your stack. There are a number of options out there. Some are elegant and advanced like Puppet + Vagrant, other are simple and quick like XAMPP. I use XAMPP whenever I can't or won't do native LAMPP stacks (or MAMPP) if nothing else for it's versatility and consistency across platforms.
Once you've built LAMPP stacks from scratch you get used to some of the nice features it has. One of my favorites is the Virtual Document Root, which allows you to map a folder structure pattern to a single virtual host entry, therefore eliminating the need for separate vhost entries on your Apache conf. What that means is that if I go to http://drupal the files will be served from /workspace/drupal and if go to http://rob the files will be served from /workspace/rob and that is pretty convenient.
First of all, I am on a Mac, but PC users can follow this replacing the paths with their own paths. On my Mac I start by creating a workspace folder on the very root folder.
$ sudo mkdir /workspace $ sudo chmod a+rw /workspace
In there I will create one folder per domain I am working on.
$ cd /workspace; $ mkdir rob;
Then we need to add an entry to the hosts file to make sure our browsers ping our local Apache service. For quicker access I place a symbolic link (symlink) on my desktop, like this:
$ sudo ln -s /private/etc/hosts ~/Desktop/hosts;
You can easily append a new entry at the bottom of the hosts file like this:
$ echo "127.0.0.1 rob" >> ~/Desktop/hosts;
And now you should be able to point your web browser to http://rob and get your website.
So how did we accomplish this?
This is what my httpd-vhosts.conf file looks like:
NameVirtualHost *:80 # ===================================== # V I R T U A L D O C R O O T # ===================================== <virtualhost *:80> ServerName workspace ServerAlias * ServerAdmin firstname.lastname@example.org UseCanonicalName Off VirtualDocumentRoot /workspace/%0 ErrorLog "logs/error.log" CustomLog "logs/access.log" common <directory /workspace> AllowOverride All Options Indexes FollowSymLinks ExecCGI Includes Order allow,deny Allow from all </directory> </virtualhost> # # You can still do overrides on a per case basis, for example when the # pattern of your web application does not match your # VirtualDocumentRoot pattern. Such is the case of Drupal sites hosted # on the Acquia cloud hosting infrastructure. # <virtualhost *:80> ServerName acquia ServerAdmin email@example.com DocumentRoot "/workspace/acquia/docroot" ErrorLog "logs/acquia-error_log" CustomLog "logs/acquia-access_log" common <directory /workspace/acquia> AllowOverride All Options Indexes FollowSymLinks ExecCGI Includes Order allow,deny Allow from all </directory> </virtualhost>