Creating Simple Virtual Hosts With mod_mysql_vhost On Lighttpd (Ubuntu 12.04)
|
Submitted by falko (Contact Author) (Forums) on Sun, 2012-09-02 16:44. :: Ubuntu | Web Server | Lighttpd | MySQL
Creating Simple Virtual Hosts With mod_mysql_vhost On Lighttpd (Ubuntu 12.04)Version 1.0 This guide explains how you can use mod_mysql_vhost to create simple virtual hosts on a lighttpd web server on Ubuntu 12.04. With mod_mysql_vhost, lighttpd can read the vhost configuration from a MySQL database. Currently, you can store the domain and the document root in the MySQL database which results in very simple virtual hosts. If you need more directives for your vhosts, you'd have to configure them in the global section of lighttpd.conf, which means they'd be valid for all vhosts. Therefore, mod_mysql_vhost is ideal if your vhosts differ only in the domain and document root. I do not issue any guarantee that this will work for you!
1 Preliminary NoteBecause we must run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing sudo su
2 Installing MySQL 5.0First we install MySQL 5 like this: apt-get install mysql-server mysql-client You will be asked to provide a password for the MySQL root user - this password is valid for the user root@localhost as well as root@server1.example.com, so we don't have to specify a MySQL root password manually later on: New password for the MySQL "root" user: <-- yourrootsqlpassword
3 Installing Lighttpd And mod_mysql_vhostYou can install lighttpd (if it's not already installed) and mod_mysql_vhost as follows: apt-get install lighttpd lighttpd-mod-mysql-vhost To enable mod_mysql_vhost, we open /etc/lighttpd/lighttpd.conf and add/enable "mod_mysql_vhost", in the server.modules stanza: vi /etc/lighttpd/lighttpd.conf
Afterwards, we restart lighttpd: /etc/init.d/lighttpd restart
4 Configuring mod_mysql_vhostNow we log in to MySQL... mysql -u root -p ... and create the database lighttpd: CREATE DATABASE lighttpd; Next we create a database user (which we name lighttpd as well) with SELECT privileges for the lighttpd database: GRANT SELECT ON lighttpd.* TO lighttpd@localhost IDENTIFIED BY 'secret'; (Replace secret with a password of your choice.) Then we create the domains table in the lighttpd database and leave MySQL: USE lighttpd; CREATE TABLE domains ( quit; Now we open /etc/lighttpd/lighttpd.conf and add the following mod_mysql_vhost configuration at the end of the file: vi /etc/lighttpd/lighttpd.conf
(Replace secret with the password you've previously set for the lighttpd MySQL user.) Restart lighttpd: /etc/init.d/lighttpd restart Now it's time to configure virtual hosts...
5 Configuring Virtual HostsI will now configure two virtual hosts, one for www.example.com (with the document root /var/www/www.example.com/web) and one for www.example.org (with the document root /var/www/www.example.org/web). First, we create the document roots of both web sites (if they don't already exist): mkdir -p /var/www/www.example.com/web Then we log in to MySQL... mysql -u root -p USE lighttpd; ... and create the vhosts as follows: INSERT INTO domains VALUES ('www.example.com','/var/www/www.example.com/web/'); We can now leave the MySQL shell: quit; That's it, the vhosts are now configured and working, and no lighttpd restart is required. To check if the vhosts are working as expected, we create an index.html file in each document root, one with the string "www.example.com" in it, the other one with the string "www.example.org"... echo "www.example.com" > /var/www/www.example.com/web/index.html and call http://www.example.com and http://www.example.org in a browser. http://www.example.com should show www.example.com, and http://www.example.org should display www.example.org.
6 Links
|




Recent comments
1 day 14 hours ago
1 day 16 hours ago
2 days 4 hours ago
2 days 7 hours ago
2 days 11 hours ago
2 days 17 hours ago
3 days 3 hours ago
3 days 5 hours ago
3 days 13 hours ago
3 days 14 hours ago