Saturday, January 5, 2008

Debian + lighttpd + php5 + phpmyadmin + virtual hosts

I installed a webserver with Debian GNU/Linux etch tonight. I wanted to set up ligttpd, phpmyadmin and vhosts, which proved to be easy enough.

1. Installation

apt-get install php4-cgi lighttpd phpmyadmin

2. Enable PHP

To get PHP working, run the following command
lighty-enable-mod fastcgi
3. Get phpmyadmin running

To configure phpmyadmin, add the following to your lighttpd.conf
alias.url = ( "/phpmyadmin" => "/usr/share/phpmyadmin" )
Please note there are no trailing slashes, which enables us to reach phpmyadmin from both of these:

example.com/phpmyadmin
example.com/phpmyadmin/

4. Configure vhosts

I want my site to be reachable from www.example.com and example.com. I also want my users to be able to reach their personal pages, located in ~/public_html, from username.example.com.

This was my solution:
$HTTP["host"] =~ "^(www\.)?example\.com$" {
evhost.path-pattern = "/var/www/"
alias.url = ( "/phpmyadmin" => "/usr/share/phpmyadmin" )
}
else $HTTP["host"] =~ "example\.com" {
evhost.path-pattern = "/home/%4/public_html/"
}
Note I have moved the configuration for phpmyadmin so it can not be reached from the users' subdomains.

5. SSL

For added security, run the following in the directory /etc/lighttpd.
lighty-enable-mod ssl
openssl req -new -x509 -keyout server.pem \
-out server.pem -days 365 -nodes
Hope this helps.