»My software»for lighttpd»mySQL vhosts 
mySQL vhosts

This is a simple trick to provide vhosts information from DB to lighttpd.
(You can use the same method to feed any dynamic data to lighttpd)


Function include_shell is our best friend
This function execute external command capture output and feed lighttpd config

So add to lighttpd.conf:

include_shell "/etc/lighttpd/show_user_conf.php"

The script show_user_conf.php is something like this one (chmod 755 before use ;')

#!/usr/bin/php
<?
$MYSQL_HOST = "localhost";
$MYSQL_USER = "db_user";
$MYSQL_PASS = "db_password";
$MYSQ_DB      = "db";

echo "### VHOSTS ###\n\n";

$mysql = mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS);
mysql_select_db($MYSQL_DB);
$q = "SELECT * FROM vhosts_table ..."; // use your imagination
$result = mysql_query($q, $mysql);
while ($row = mysql_fetch_object($result))
{
   echo '$HTTP["host"] == "' . $row->sub_domin . "." . $row->domain . '" {' . "\n";
   echo '   server.document-roow = "' . $row->doc_root . '"' . "\n";
   echo '   accesslog.filename   = "' . $row->access_log . '"' . "\n";
   ... // add everything you need for this vhost
   ... // ... and don't forget to get info from DB :'P
   echo '}' . "\n";
}

?>

It's easy ... yeah ?;')

This solution is not perfect. You need to restart lighttpd when you need new configuration ... but ... nobody is perfect ;') I still hope that lighttpd will provide something like -HUP and then ... :'P



Bugs, Patches and Suggestions

Send me E-Mail: drJeckyll@Jeckyll.net


Comments

Still no comments posted


write new comment

stretch
stretch
stretch
stretch
interoffice
interoffice
interoffice
interoffice