Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make a virtual host in Apache with dynamic configuration for my websites. For example something like this would be perfect.

<VirtualHost *:80>
    AssignUserId $domain webspaces
    ServerName $subdomain.$domain.$tld
    ServerAdmin admin@$domain.$tld
    DocumentRoot "/home/webspaces/$domain.$tld/subdomains/$subdomain"
    <Directory "/home/webspaces/$domain.$tld/subdomains/$subdomain">
    php_admin_value open_basedir "/tmp/:/usr/share/pear/:/home/webspaces/$domain.$tld/subdomains/$subdomain"

$subdomain, $domain, $tld would be extracted from the HTTP_HOST variable using regex at request time. No more loads of configuration, no more apache reloading every x minutes, no more stupid logic.

Notice that I use mpm-itk (AssignUserId directive) so each virtual host runs as a different user. I do not intend to change this part.

Since now I have tried:
- mod_vhost_alias but this allows dynamic configuration of only the document root.
- mod_macro but this still requires the arguments of the vhost to be declared explicitly for each vhost.
- I have read about mod_vhs and other modules which store configuration in a SQL or LDAP server which is not acceptable as there is no need for configuration! Those 3 necessary arguments can be generated at runtime.
- I have seen some Perl suggestions like this, but as the author states $s->add_config would add a directive after every request, thus leading to a memory leak, and $r->add_config seems not to be a feasible solution.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.