LightTPD
From Gentoo Linux Wiki
|
Contents |
[edit] Subpages
[edit] Installation
In this section, we will set USE flags and emerge the required package(s).
[edit] USE flags
The possible USE flags for LightTPD are:
- bzip2 - Enable bzip2 support for mod_compress
- fastcgi - Enables FastCGI support (needed if you want to use PHP)
- gdbm - Enables support for the GNU database libraries
- ipv6 - Enables IPv6 Support
- lua - Enables Lua Support (If you want mod_cml, enable this)
- memcache - Enables Memcache support (Again, for mod_cml)
- mysql - Enables MySQL support, for mod_mysql_vhost
- pcre - Enables PCRE support, if you want to use regex in your configuration files
- php - Enables mod_fastcgi/php settings
- rrdtool - Enables RRDtool support for some cool graphs
- ssl - Enables OpenSSL support, for HTTPS
- doc - Enables the installation of documentation
- fam - Enables fam/gamin for reducing number of stat() calls
- ldap - Enables LDAP support
- minimal - Installs a minimal installation; no docs nor unused modules
- webdav - Enables WebDAV support
- xattr - Enable extended attribute support
| Code: Using euse to display USE information |
% euse --info bzip2 |
| Code: Using euse to add USE flags to /etc/make.conf |
% euse -E bzip2 |
Choose the USE flags you want to use, and add them to your /etc/make.conf. If you don't want to make all of these USE flags in your system, just for LightTPD you can use /etc/portage/package.use. To add your USE flag to your /etc/portage/package.use, this might help:
| Code: Add your USE flags to /etc/portage/package.use |
% echo "www-servers/lighttpd <your useflag selection here with space separation>" >> /etc/portage/package.use |
[edit] Emerging LightTPD
| Code: Emerging LightTPD |
# emerge -av lighttpd |
[edit] Configure
[edit] Base Configuration
Fire up your editor to /etc/lighttpd/lighttpd.conf and lets get started editing. We won't cover more advanced things such as FastCGI, mod_simple_vhost, mod_cml, etc. Go though the configuration file and edit anything that you feel you need to edit.
[edit] PHP support
PHP support needs to be activated manually.
[edit] Check for FastCGI support
Your USE flags for FastCGI should include php and fastcgi. To check for FastCGI support, run php-cgi -v and look for "cgi-fcgi" in the version output. If you don't see this, try emerging PHP again after setting the USE flag cgi for the package dev-lang/php: emerge -av dev-lang/php.
See PHP for further information on how to set up PHP.
[edit] Enable FastCGI support
Open up your /etc/lighttpd/lighttpd.conf file with your favorite editor, and uncomment the line that looks like this:
| Code: Line to uncomment |
#include "mod_fastcgi.conf" |
Then, open up your /etc/lighttpd/mod_fastcgi.conf file, and uncomment the large block of code. In general it is already pre-configured so that you can move on with testing your setup. If needed, you can also modify the "bin-path" according to your PHP installation:
| File: /etc/lighttpd/mod_fastcgi.conf |
... "bin-path" => "/usr/bin/php-cgi" ... |
You should enable cgi.fix_pathinfo in your php.ini. This makes your PATH_INFO and PHP_SELF variables usable with LightTPD otherwise many scripts will not work properly for you.
| File: /etc/php/cgi-php5/php.ini |
... cgi.fix_pathinfo = 1 ... |
[edit] vhosts
| File: /etc/lighttpd/lighttpd.conf |
simple-vhost.server-root = "/full/path/to/server/root"
simple-vhost.default-host = "FQDN"
simple-vhost.document-root = "/"
$HTTP["host"] =~ "^(www.)?FQDN" { server.document-root = "/full/path/to/server/root" }
|
[edit] user directories
Add mod_userdir to the list of modules to load.
| File: /etc/lighttpd/lighttpd.conf |
userdir.path = "public_html" userdir.exclude-user = ( "abuser", "guyidontlike", "exbf" ) |
[edit] dynamic MySQL vhosts
We are going to setup LightTPD to support vhosts in a MySQL database.
First, edit your lighttpd.conf configuration file to include the MySQL options.
| File: /etc/lighttpd/lighttpd.conf |
# {{{ mod_mysql_vhost
mysql-vhost.db = "lighttpd"
mysql-vhost.hostname = "<datebase_host_ip>"
mysql-vhost.user = "<your_dbuser>"
mysql-vhost.pass = "<your_dbuser_pass>"
mysql-vhost.sock = "/var/run/mysqld/mysqld.sock"
mysql-vhost.sql = "SELECT docroot FROM domains WHERE domain = '?';"
# }}}
|
Create an mysql database and create the table.
| Code: Creating the database |
mysql#>create database lighttpd; mysql#>use lighttpd; mysql#>CREATE TABLE `domains` ( `domain_id` int(11) NOT NULL auto_increment, `domain` varchar(64) NOT NULL, `docroot` varchar(128) NOT NULL default '' PRIMARY KEY (`domain_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; |
Insert vhosts with phpMyAdmin or with the command line. Just fill the fields 'domain' and 'docroot'. Make sure that lighttpd has proper rights to the docroot folder.
[edit] Tweaking using dynamic activate/deactivate option
We need to tweak these settings to support multiple LightTPD servers on a single MySQL database. We'll also include support for enabling/disabling vhosts in the database, without deleting the vhost.
Edit the LightTPD configuration file. The SQL query needs some adjustment in order to support multiple server and dynamic enabling/disabling of vhosts. The query in the configuration can be adapted to your needs. Just make sure that the vhost name is return in a single field, called domain.
| File: /etc/lighttpd/lighttpd.conf |
mysql-vhost.sql = "SELECT docroot FROM domains WHERE server = '<lighttpd_server_ip>' AND enabled = 'y' AND domain = '?';" |
Now add the two fields to your LightTPD domains table
| Code: Alter the table |
mysql#>ALTER TABLE domains ADD `server` varchar(15) NOT NULL, `enabled` enum('y','n') NOT NULL;
|
You can now fill the field 'server' with the IP Address of the lighttpd server running the vhost. To enable the vhost, set the 'enabled' field to 'y'. To disable an vhost, set the 'enabled' field to 'n'. Changes are immediately effective. This can be perfectly implemented to a hosting company.
[edit] Compression
[edit] Static compression (HTML)
Firstly you need to activate the "mod_compress" module. This is done by commenting out "mod_compress" in /etc/lighttpd/lighttpd.conf. Finally it should look like:
| File: /etc/lighttpd/lighttpd.conf |
server.modules = (
...
"mod_compress",
...
)
|
Then you need to create a directory where all the cache-files are being stored. We're using /tmp/lighttpd/cache/compress. By default, LightTPD will store those files in /var/lib/lighttpd/cache/compress.
mkdir -p /tmp/lighttpd/cache/compress
The compression directory mentioned in the cache-dir line should be owned by the user who runs the LightTPD daemon. Now we set the new path in the lighttpd.conf and enable compression for the content-types text/plain and text/html.
| File: /etc/lighttpd/lighttpd.conf |
compress.cache-dir = "/tmp/lighttpd/cache/compress/"
compress.filetype = ("text/plain","text/html")
|
[edit] Dynamic compression (PHP)
To enable dynamic compression, you need to enable zlib.output_compression in your php.ini:
| File: php.ini |
zlib.output_compression = On |
To find out the path of your php.ini, check the output of:
| Code: Show PHP's configuration file names |
php --ini |
[edit] Starting LightTPD
To start LightTPD, you can use the init scripts provided:
| Code: Starting LightTPD |
# /etc/init.d/lighttpd start * Starting lighttpd ... [ ok ] |
Point your web browser to http://127.0.0.1/, and, if you are successful, you should get a 404 Not Found. All files are stored in /var/www/localhost/htdocs. If LightTPD did not start up properly, check out the file /var/log/lighttpd/error.log
[edit] Starting LighTPD when your computer boots
This will add LightTPD to the default run level of your computer:
| Code: Adding LightTPD to the default run level |
# rc-update add lighttpd default * lighttpd added to runlevel default |

