HOW-TO: Setup XAMPP to use VirtualDocumentRoot in Mac OS X

Aug 22, 2016

I had a lot of trouble upgrading my XAMPP to run the latest PHP. So much so, that I decided to document what I did.

First off, I downloaded the Mac version of XAMPP available from Apache Friends. I probably could use OS X’s built-in Apache server, but XAMPP is portable and in order to keep things consistent from platform to platform I tend to like it better. Make sure you disable Apache by unchecking the “Web Sharing” option of the “Sharing” system preference pane.

If you browse to http://localhost you should see a XAMPP splash page. Success! Next, go back to the XAMPP website and download the devel package, this will install and tweak the settings of the basic install to give you better development tools.

Now some configuration. Other than the usual ramping up the memory and defining the available resources you will need to setup at least one Virtual Host to use Virtual Document Root

XAMPP will serve pages from /Applications/xampp/xamppfiles/htdocs. I keep my websites on a special folder located at /workspace (often times it's just a symlink to another folder somewhere) so we will need to make some adjustments.

The idea here is that I can create folders under /workspace like /workspace/rob and be able to get to them via http://rob without having to edit the vhosts file.

In order to keep things clean I created a new file called /Applications/xampp/xamppfiles/etc/extra/httpd-dynamic-vhosts.conf with the following:

$ sudo vim /Applications/xampp/xamppfiles/etc/extra/httpd-dynamic-vhosts.conf

<VirtualHost *:80>
UseCanonicalName Off
VirtualDocumentRoot /workspace/%0
<Directory "/workspace">
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Notice VirtualDocumentRoot and %0 are ONLY available if you load mod_vhost_alias.so.

Next, I included the above .conf file, by adding the following line to the bottom of /Applications/xampp/xamppfiles/etc/httpd.conf:

$ sudo vim /Applications/xampp/xamppfiles/etc/httpd.conf

Include /Applications/xampp/etc/extra/httpd-dynamic-vhosts.conf

Now let's restart Apache and try to load http://rob. Voilá, success!


Engineering Leadership

Get notified about updates and be the first to get short and concise articles.

By subscribing to my newsletter you accept to receive recurring emails about the services I offer and personal opinion pieces.

Proudly published using Prismic