mod_vhost_cdb (Robert Schulze <rob at rob-schulze.de>)
... is yet another virtualhosts-from-db module for the Apache (>=2) webserver.
It uses tinycdb to store the configuration of each domain.
Installation
You should have the tinycdb-package installed, including development headers.
NOTE: When running FreeBSD, make tinycdb with CFLAGS+=-fPIC, otherwise the module can't be build.
Download and unpack the archive, then edit the Makefile:
APXS=/usr/bin/apxs2
LIBS= -lcdb -L/usr/lib/ -I/usr/include/
You should set APXS to a value appropriate to your environment (try: $ which apxs or $ which apxs2).
Furthermore, alter /usr/lib and /usr/include according to the standard path of libraries and header-files.
Now you can safely run (make install must be run as superuser):
$ make
# make install
After that, the module gets copied to the directory where all apache modules reside and your httpd.conf (or what else your main server configfile is) gets updated, so that apache loads the module upon startup.
Configuration
Just have a look at the sample httpd.conf in the tarball.
Here is what your configuration may look like:
<VirtualHost *>
VhostCDB_Engine on /* enable mod_vhost_cdb */
VhostCDB_File /etc/apache2/vhosts.cdb /* set path to cdb file to use */
VhostCDB_DefaultHost www.mvcdb-0.de /* use this entry when no hostname was transferred */
</VirtualHost>
The CDB file specified by VhostCDB_File is a binary (constant)db that gets created out of a plain input file whose format is defined in the following way:
[domainname][space][key1]=[value1]([tab][key2]=[value2]([tab][keyX]=[valueX]))
example:
www.example.com DocumentRoot=/home/www/example.com ScriptAlias=/home/www/example.com/cgi-bin UID=1000 GID=1000
You at least have to provide these four configuration keys shown above for each domain.
NOTE: you have to separate the "key=value"-pairs by tabs!
Once you finished creating your input file (here: vhosts.cdb.in), lets create a cdb out of it.
# cdb -mc /etc/apache2/vhosts.cdb < vhosts.cdb.in
Thats all.
If you add/delete/modify any virtualhost in the input file, just run that commandline.
The webserver does not need to be restarted, the replacement of the database is an atomic operation.
Advanced shit
You can place any values into the configuration and export them to:
- the environment of any cgi-application
- the request-notes of any request (maybe interesting for apache-module-hackers)
<VirtualHost *>
VhostCDB_Engine on /* enable mod_vhost_cdb */
VhostCDB_File /etc/apache2/vhosts.cdb /* set path to cdb file to use */
VhostCDB_DefaultHost www.mvcdb-0.de /* use this entry when no hostname was transferred */
VhostCDB_ExportToRequestNotes LogSQLTransferLogTable /* export the value of LogSQLTransferLogTable to request->notes */
</VirtualHost>
That piece of configuration will (well, at least if you build mod_log_sql with my mod_log_sql-patches) configure mod_log_sql to log to the a specific table ("LogSQLTransferLogTable=foobar_log" in CDB).
So you can define a LogSQLTransferLogTable for each hosted domain and make simply use of that access-log module.
<VirtualHost *>
VhostCDB_Engine on /* enable mod_vhost_cdb */
VhostCDB_File /etc/apache2/vhosts.cdb /* set path to cdb file to use */
VhostCDB_DefaultHost www.mvcdb-0.de /* use this entry when no hostname was transferred */
VhostCDB_ExportToEnv PHPRC /* export the value of PHPRC to environment of cgi-processes */
</VirtualHost>
This will export the environment-variable PHPRC according to the settings in your cdb.
You may define a separate php.ini for each domain in this way.
NOTE: You may of course export mutiple values, just separate them with a space character.
Advanced shit 2
Instead of hosting the domain locally, you can also define redirect urls:
www.example.com Redirect=http://www.example.net/
redirects every request to www.example.com to www.example.net.
One can also define mod_vhost_alias-like domains - but very limited!
*.example.com DocumentRoot=/home/www/example.com/-subdomain-%1 ScriptAlias=/home/www/example.com/-subdomain-%1/cgi-bin UID=1000 GID=1000
will dynamically map any xyz.example.com to /home/www/example.com/-subdomain-xyz/
Download