- Lighttpd
- Andre Bogus
- 519字
- 2021-08-25 18:06:22
MySQL based Virtual Hosting
To have the freedom to put our sites up anywhere we want, we can use mod_mysqlvhost
. This module reads the document root for a domain from a MySQL database table and will thus need a running MySQL server. mod_mysqlvhost
gives the maximum flexibility, usually at a small performance cost.
Many Web projects already use MySQL as a backend database, so the cost of running MySQL does not need to be taken into the calculation. For all other installations, the cost of running a MySQL server would probably not be worth the additional flexibility.
Installing MySQL
First, we need to download MySQL. The MySQL download site, available under http://www.mysql.com/downloads/mysql/, links to mirrors that have packages for almost all systems. To pick the optimal package source, here are my recommendations:

The options file fo Windows installations should include the following lines (given that you have installed MySQL in C:\mysql):
[mysqld] basedir=C:/mysql # note the / instead of \ datadir=C:/mysql/data
The installers usually set up their own options file.
Bringing MySQL and mod_mysqlvhost Together
mod_mysqlvhost
is as flexible as possible you can create your database the way you want it. The only thing that is really needed is a table with at least two columns, one of which contains the domain name and the other the path. Both are usually stored as VARCHARs
. A possible database setup SQL script might be:
GRANT SELECT ON domains.* TO lighttpd@localhost
IDENTIFIED BY '********';
CREATE DATABASE domains;
USE domains;
CREATE TABLE domains (
domain VARCHAR(64) not null primary key,
document_root VARCHAR(256) not null);
The corresponding Lighttpd configuration is:
mysql-vhost.db = "domains" mysql-vhost.user = "lighttpd" mysql-vhost.password = "********" mysql-vhost.sock = "/var/sock/mysql.lighttpd.sock" mysql-vhost.sql = "SELECT document_root from domains WHERE domain=?"
Of course, we should take a password not only consisting of asterisks. Adding, moving, and deleting domains can now be done with the following SQL:
# Add a domain INSERT INTO domains VALUES ('subdomain.ourdomain.net', '/var/www/sub1'); # Move a domain to another directory UPDATE domains SET document_root = '/var/www/subdomain' WHERE domain = 'subdomain.ourdomain.net'; # Delete a domain DELETE FROM domains WHERE domain='subdomain.ourdomain.net'; # Change a domain name by deleting the old and adding a new entry.
Now we have everything in place to be completely free with our domain to document root mapping.
Note
MySQL Administration Programs
MySQL comes with a very minimal command line client. To speak with the server more comfortably, the following programs might help:
MySQL Gui Tools come from the same folks as the MySQL database itself, so they are easily the tool of choice when it comes to working with MySQL.
phpMyAdmin from http://phpmyadmin.net is a CGI-based tool written in PHP. It even works with Lighttpd. To learn to install it, read chapter 9.
Java SQL Admin Tool can work with MySQL and is completely written in Java, so it "runs everywhere" according to the Sun Microsystems marketing slogan. Find it at http://www.trash.net/~ffischer/admin/index.html.
Under Linux, both Gnome and KDE have MySQL administration programs (Gnome MySQL client and KNoda). Lastly, go to http://freshmeat.net and search for "MySQL admin".
- Painter 現代服裝效果圖表現技法
- 中文版3ds Max 2016/VRay效果圖制作實戰基礎教程
- OpenStack實戰指南
- PPT設計實用教程
- 中文版Illustrator CC實用教程
- Drools規則引擎技術指南
- CorelDRAW X5實用教程(第2版)
- Adobe創意大學InDesign CS5 版式設計師標準實訓教材
- 工業軟件研發、測試與質量管理論叢
- Android從入門到精通
- SolidWorks 2018有限元:運動仿真與流場分析自學手冊
- Word-Excel-PowerPoint 2010三合一辦公應用實戰從入門到精通(超值版)
- Power Query For Excel:讓工作化繁為簡
- Photoshop+CorelDRAW平面設計實例教程(第3版)
- SPSS統計分析與應用