Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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">
        ....
    </Directory>
    php_admin_value open_basedir "/tmp/:/usr/share/pear/:/home/webspaces/$domain.$tld/subdomains/$subdomain"
</VirtualHost>

$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

 
discard

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

Browse other questions tagged or ask your own question.