Debian lighttpd server
From Kurobox Central
Contents |
[edit] Installation in Debian
Switch to debian unstable (needed as lighttpd is not yet available in stable debian)
nano /etc/apt/sources.list replace stable to unstable in "deb" lines //deb http://security.debian.org stable/updates main contrib //deb ftp://ftp.fr.debian.org/debian unstable main contrib //deb ftp://ftp.de.debian.org/debian-non-US stable/non-US main contrib //deb-src ftp://ftp.fr.debian.org/debian unstable main contrib //deb-src ftp://ftp.de.debian.org/debian-non-US stable/non-US main contrib
Install Lighttpd + PHP5 + SQLite support
apt-get install lighttpd php5-cgi php5-sqlite
Answer yes to all and ignore the errors (the one about exim is normal as you do not have exim !)
[edit] Configuration of lighttpd
[edit] General configuration
- Default configuration only allow localhost to connect the server, just remove that :
nano /etc/lighttpd/lighttpd.conf // comment the line server.bind = "localhost"
=>
#server.bind = "localhost"
- If you need to run some applications with root privileges in some of your scripts :
Run lighttpd server with root privileges :
// comment the lines server.username = "www-data" // and server.groupname = "www-data"
[edit] add PHP5 support
- You need to edit a config file as it's configured to run php4 :
nano /etc/lighttpd/conf-available/10-fastcgi.conf
// replace
"bin-path" => "/usr/bin/php4-cgi",
// with
"bin-path" => "/usr/bin/php-cgi",
- then activate fast-cgi and cgi modules :
cd /etc/lighttpd/conf-enabled ln -s ../conf-available/10-cgi.conf 10-cgi.conf ln -s ../conf-available/10-fastcgi.conf 10-fastcgi.conf
[edit] Authentification
You may want to protect your server with some users/passwords :
- Edit the authentification's config file :
nano /etc/lighttpd/conf-available/10-auth.conf
and add these lines :
auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "/var/www/.htpasswd"
auth.require = ("/dir1" =>
(
"method" => "basic",
"realm" => "Kurobox",
"require" => "valid-user"
),
"/dir2" =>
(
"method" => "basic",
"realm" => "Kurobox",
"require" => "user=tom|user=john"
),
)
Adapt auth.require to you needs :
You can set a configuration for any directory you want
"realm" field is a text that will be shown in the authentification window
"require" field allow to specify which users will be alowed to a specific folder. Valid values are :
valid-user : every declared users will be authorized
user=user1 : user1 will be authorized
group=group1 : members of group1 will be authorized
host=xxx.xxx.xxx.xxx : host with specified ip is allowed to connect the folder
You can specify several users/group/hosts by separating them with "|" :
"require" => "user=bob|user=dad|group=www-users|host=192.168.1.2"
- then activate auth module :
cd /etc/lighttpd/conf-enabled ln -s ../conf-available/10-auth.conf 10-auth.conf
- Create your user list with passwords :
The file containing all you users/passwords will be /var/www/.htpasswd (unless you changed it in mod-auth's configuration). To create it and add users, you'll need "htpasswd" tool that is a part of Apache utils. To install it :
apt-get install apache2-utils
Then add your users :
htpasswd -c -b /var/www/.htpasswd user password # -c is only for the first user as it creates the file htpasswd -b /var/www/.htpasswd user2 password2 # to add more users, remove the -c option ...
[edit] Restart lighttpd
Once everything is configured, you can restart lighttpd to apply modifications :
/etc/init.d/lighttpd restart
