Kevin's Worklog

Documenting the Daily Stream

Simple Apache Configuration for Multiple Dev Sites

I often want to run different apps (Drupal, Omeka, BaseX, etc.) on my dev machine. What follows is a simple Apache configuration that, with the help of a Linux system’s /etc/hosts file, makes this “multiple sites on a single machine” configuration easy.

The first thing to do is to configure each of these “sites” in the system’s /etc/hosts file. The following is the configuration for a dev machine that has a Drupal site, Omeka site, and static site.

127.0.0.1   localhost omeka drupal
127.0.1.1   ksclarke-laptop

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Next, we’ll need a configuration for each of the virtual hosts in the Apache config file. The most basic configuration, would look like:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
    ServerAdmin ksclarke@gmail.com
    DocumentRoot /var/www/html

    LogLevel info
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Location />
            Order deny,allow
            Allow from all
    </Location>
</VirtualHost>

<VirtualHost *:80>
    ServerName drupal
    ServerAdmin ksclarke@gmail.com
    DocumentRoot /var/www/drupal

    LogLevel info
    ErrorLog ${APACHE_LOG_DIR}/drupal-error.log
    CustomLog ${APACHE_LOG_DIR}/drupal-access.log combined

    <Location />
            Order deny,allow
            Allow from all
    </Location>
</VirtualHost>

<VirtualHost *:80>
    ServerName omeka
    ServerAdmin ksclarke@gmail.com
    DocumentRoot /var/www/omeka

    LogLevel info
    ErrorLog ${APACHE_LOG_DIR}/omeka-error.log
    CustomLog ${APACHE_LOG_DIR}/omeka-access.log combined

    <Location />
            Order deny,allow
            Allow from all
    </Location>
</VirtualHost>

Each of these virtual host configurations could be put into their own config file (for instance, on Ubuntu in /etc/apache2/sites-available (with a link created in /etc/apache2/sites-enabled)), but I tend to reserve individual configuration files for real world hosts: worklog.kevinclarke.info, www.kevinclarke.info, etc. Instead, I put the above in the default virtual host config file.

Once the above are configured, accessing each site is as simple as going to http://drupal/ or http://omeka/ in a Web browser.

For apps that are proxied, individual mod_proxy configurations can be put in the relevant VirtualHost configuration.