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.

XAMPP comes with mod_vhost_alias enabled by default, but the sample httpd-vhosts.conf does not come with an implementation example. Worry not, that is why I've written this blog post :)

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 roberto@montero-ortiz.com
  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 roberto@montero-ortiz.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>

Hope this helps. If you have questions or comments drop me a line using the contact form or send me a message via Twitter at @rmonteroo

Rob Montero

Rob Montero, Drupal Association Individual Member

Roberto Montero Ortiz is an individual member of the Drupal Association, which fosters and supports the Drupal software project, the community and its growth. He also has an active role in the Drupal Community in Costa Rica and regularly contributes to Drupal Camps held in Latin America.

Rob Montero, Acquia Certified Developer 2014   Rob Montero, Certified Developer Back End Specialist 2015Rob Montero, Acquia Certified Developer Front End Specialist

Rob is also an Acquia Certified Developer, awarded with the Grand Masters title after completing his third certification within a year. 

Zend also certifies Rob's knowledge of PHP OOP skills, but at this point this block is getting a bit presumptious. Suffice it to say, Rob is competitive and competent. He's also a nice guy all around.

Drupal Latin America

Rob Montero is a proud sponsor and mentor of young Drupal talent of the Costa Rican Drupal Users Group and entrepreneur at Drupal Latin America

CHECK THEM OUT

Get in touch

  • Rob Montero
    Ave Popocatepetl 435 B 504
    Sta Cruz Atoyac, Benito Juarez
    Ciudad de México, 03310 
  • (858) 952 0762
  • roberto@montero-ortiz.com
Signup to our newsletter: