This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Page tree
Skip to end of metadata
Go to start of metadata


Here you'll find an example of how to do name-based virtual hosting using mod_perl and mysql.

This works for my needs but most likely you will have to change parts to get what you want. Everything covered here is fairly advanced and I'll assume you know your way around Apache, MySQL and Perl.

I tried to make it as portable as possible. It should work with a minimum changes on any Linux system, and with more on Windows as well.

Note: If you experience problems you can try to contact me on #httpd (ask for sjorge)


  1. perl 2. httpd 2.2
    1. mod_perl 2. mod_dav / mod_dav_fs 3. mod_authn_dbd 4. mod_ftp (can be left out – changes to the files are needed) 5. libphp5 (can be left out – changes to the files are needed)
      3. MySQL server (another database server will work if there are DBI and DBD drivers available – changes to the files are needed)

General Setup

Configuration Layout






Main configuration file


Host configuration file


Virtual host template


WebDAV virtual host template


FTP virtual host template


hosts base path

Virtual Host Layout (relative to /srv/hosts)




Virtual host base dir


Holds varies other files


Logs for host


temp directory for php


sessions directory for php


cgi-bin for host (only works when CGI is set in database)


document root

Setting up the database

First we need a database to hold our host configuration.

Use the MySQL client, or phpMyAdmin, or some other means, to create the database. You can get the database template here

You also need to create a user with access to that database. I chose to call mine apache

  • more information on the database will follow later

Configuring httpd

Note: Replace /srv/httpd with your own ServerRoot!!

Download all .conf and .tmpl files provided in the General Setup section and save them in the correct locations.

Edit httpd.conf and change:

Edit hosts.conf and change:

  • db server
  • db database
  • db user
  • db pass
  • host http_tmpl path (full path!)
  • host dav_tmpl path (full path!)
  • host ftp_tmpl path (full path!)
  • host path (full path!)

Edit http.tmpl and webdav.tmpl and change:

You should be good to go. Feel free to make more changes to the templates and configuration files

Adding a host

Use the MySQL client or phpMyAdmin, or another means, to access the database.

adding host entry

INSERT INTO hosts VALUES(null, 'localhost', 1, 0, 0, 0, 0, 0);




auto-increment host ID


host name


enable (0 to disable the host)


disable WebDAV (1 to enable)


disable FTP (1 to enable)


disable CGI (1 to enable)


disable Server Side Includes (1 to enable)


disable PHP (1 to enable)

(Re)start httpd and the new vhosts will be available (you need to provide the -DDAV flag to enable WebDAV on the server)

Note: The directories for this vhost will be created automatically when apache is (re)started! (There may be a spike in memory usage at startup.)

Note: Removal isn't automatic; if you remove a host + aliases + users + configuration the files will remain)

Note: I recommend adding localhost as your first vhost. All request with and unknown host header will go to this host.

adding users

Only required when you enable WebDAV for a host.

INSERT INTO users VALUES(null, 1, 'user', 'apache-encrypted-password', 'dav');




auto increment user id


host id user belongs too (check hosts table to get it)


user name


password for user. check httpd doc for encryption (here)


group(s) for user. dav = enables WebDAV access

adding aliases (optional)

You can create aliases for hosts as well if you wish (multiple aliases possible per host; each alias must be unique).

INSERT INTO aliases VALUES(1, 'cygnus');




host ID alias belongs too (check hosts table to get it)


alias for host

adding additional configuration options (optional)

Setting up a host as reverse proxy? not a problem (note reverse proxy config not shown).

INSERT INTO configuration VALUES(1, '#proxy config');


  • description_'


host id configuration belongs too (check hosts table to get it)

'#proxy config'

configuration for host

Alternative Methods of managing vhosts

There is a google code project that has a java based manager for this configuration. Use at own risk. This isn't professional code and isn't tied to the ASF.

accessing WebDAV

Point your WebDAV client to and long in with the user/pass combination. It works in IE, DreamWeaver, cadaver, and Mac OS X's WebDAV client.

accessing FTP

This is a bit more tricky.

pass: pass

The vhost is selected based on the username. A username without a suffix will go to the first vhost with FTP enabled.


This configuration works on both Windows and Linux (presumably Macs as well).

To get it to work on Windows you need to edit http.tmpl and update the path separate from : to ; for the php_admin_values.

Other database systems can be used by modifying the configuration files. PostrgesSQL should work fine, for example.

  • No labels