Docs ModMySQLVhost » History » Revision 19
Revision 18 (stbuehler, 2009-02-17 10:59) → Revision 19/22 (Shtirlic, 2009-03-10 16:19)
h1. Module mod_mysql_vhost - MySQL-based vhosting *Module: mod_mysql_vhost* {{toc}} {{>toc}} h2. Description With MySQL-based vhosting you can store the path to a given host's document root in a MySQL database. *Note*: Keep in mind that only one vhost module should be active at a time. Don't mix mod_simple_vhost with mod_mysql_vhost. h2. Options h3. Example: <pre> mysql-vhost.db = "lighttpd" mysql-vhost.user = "lighttpd" mysql-vhost.pass = "secret" mysql-vhost.sock = "/var/run/mysqld/mysqld.sock" mysql-vhost.sql = "SELECT docroot FROM domains WHERE domain='?';" mysql-vhost.hostname = "localhost" mysql-vhost.port = 3306 </pre> If specified, @mysql-vhost.hostname@ overrides @mysql-vhost.sock@. h3. MySQL setup: <pre> GRANT SELECT ON lighttpd.* TO lighttpd@localhost IDENTIFIED BY 'secret'; CREATE DATABASE lighttpd; USE lighttpd; CREATE TABLE domains ( domain varchar(64) not null primary key, docroot varchar(128) not null ); INSERT INTO domains VALUES ('host.dom.ain','/http/host.dom.ain/'); </pre> h2. Wildcard subdomains with same docroot Insert domain names like '%.example.com' into the sql table, and use the following query: mysql-vhost.sql = "SELECT docroot FROM domains WHERE '?' like domain;" h2. Per-vhost configuration (not using the module) You can obviously create a lighttpd config from a database (load it via the @include_shell@ command in the lighttpd config); but there is no point in using the same table again with mod_mysql_vhost - just use server.document-root. Your script should output something like that for every vhost: <pre> $HTTP["host"] == "<DOMAIN_FROM_DATABASE>" { server.document-root = "<DOCROOT_FROM_DATABASE>" <CONFIG_FROM_DATABASE> } </pre> Please note that you should not allow your users to modify the config which gets inserted here, or they just may use include_shell with "rm -rf /" - which gets probably executed with root. And you have to restart your webserver every time you change something.