Inhaltsverzeichnis

Lighttpd + PHP

Version 1.0
Stand: 10.04.2008

Author: sledge

In diesem Tutorial wird die Installation von Lighttpd und PHP für Gentoo beschrieben. Beachte bitte, es handelt sich um eine aus meiner Sicht guten Konfiguration. Diese solltest und musst du deinen persönlichen Bedürfnissen anpassen.

1.0 Lighttpd installieren

cat >> /etc/portage/package.use << "EOF"
www-servers/lighttpd fastcgi fam webdav -ipv6
dev-lang/php cgi fastcgi gd curl bcmath session calendar force-cgi-redirect gd mysql pdo gdbm truetype -threads
dev-libs/apr
EOF

Anschließend installieren wir die Pakete. Es kann ein bisschen dauern bis der Vorgang abgeschlossen wurde.

emerge lighttpd php apache-tools imagemagick mcrypt

2.0 Konfiguration Lighttpd

Wir erstellen eine lighttpd.conf. Für weitere Informationen ziehe bitte die gute Dokumentation des Lighty zu rate.

mkdir -p /var/www/domain/htdocs

cat > /etc/lighttpd/lighttpd.conf << "EOF"
server.username = "lighttpd"
server.groupname = "lighttpd"
server.document-root = "/var/www/domain/htdocs/"
server.pid-file = "/var/run/lighttpd.pid"
server.errorlog = "/var/log/lighttpd/error.log"
accesslog.filename = "/var/log/lighttpd/access.log"
accesslog.format = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
server.tag = "$DeineDomain"
server.stat-cache-engine = "simple"
server.event-handler = "linux-sysepoll"
server.name = "www.deinedomain.de"
server.max-fds = 2048
server.follow-symlink = "enable"
server.dir-listing = "disable"
server.max-keep-alive-idle = 10
server.modules = ( 
  "mod_access",
  "mod_auth",
  "mod_alias",
  "mod_evasive",
  "mod_fastcgi",
  "mod_accesslog" 
)
server.indexfiles = (
  "index.xhtml",
  "index.html",
  "index.htm",
  "index.php",
  "login.php",
)
mimetype.assign = (
 ".pdf"     => "application/pdf",
 ".sig"     => "application/pgp-signature",
 ".spl"     => "application/futuresplash",
 ".class"   => "application/octet-stream",
 ".ps"      => "application/postscript",
 ".torrent" => "application/x-bittorrent",
 ".dvi"     => "application/x-dvi",
 ".pac"     => "application/x-ns-proxy-autoconfig",
 ".swf"     => "application/x-shockwave-flash",
 ".tgz"     => "application/x-tgz",
 ".mp3"     => "audio/mpeg",
 ".m3u"     => "audio/x-mpegurl",
 ".wma"     => "audio/x-ms-wma",
 ".wax"     => "audio/x-ms-wax",
 ".ogg"     => "application/ogg",
 ".wav"     => "audio/x-wav",
 ".xbm"     => "image/x-xbitmap",
 ".xpm"     => "image/x-xpixmap",
 ".xwd"     => "image/x-xwindowdump",
 ".asc"     => "text/plain",
 ".c"       => "text/plain",
 ".h"       => "text/plain",
 ".cc"      => "text/plain",
 ".cpp"     => "text/plain",
 ".hh"      => "text/plain",
 ".hpp"     => "text/plain",
 ".conf"    => "text/plain",
 ".log"     => "text/plain",
 ".text"    => "text/plain",
 ".txt"     => "text/plain",
 ".diff"    => "text/plain",
 ".patch"   => "text/plain",
 ".ebuild"  => "text/plain",
 ".eclass"  => "text/plain",
 ".rtf"     => "application/rtf",
 ".bmp"     => "image/bmp",
 ".tif"     => "image/tiff",
 ".tiff"    => "image/tiff",
 ".ico"     => "image/x-icon",
 ".mpeg"    => "video/mpeg",
 ".mpg"     => "video/mpeg",
 ".mov"     => "video/quicktime",
 ".qt"      => "video/quicktime",
 ".avi"     => "video/x-msvideo",
 ".asf"     => "video/x-ms-asf",
 ".asx"     => "video/x-ms-asf",
 ".wmv"     => "video/x-ms-wmv",
 ".tbz"     => "application/x-bzip-compressed-tar",
 ".tar.bz2" => "application/x-bzip-compressed-tar",
 ".tar.gz"  => "application/x-tgz",
 ".bz2"     => "application/x-bzip",
 ".gz"      => "application/x-gzip",
 ".tar"     => "application/x-tar",
 ".zip"     => "application/zip",
 ".jpeg"    => "image/jpeg",
 ".jpg"     => "image/jpeg",
 ".png"     => "image/png",
 ".gif"     => "image/gif",
 ".xhtml"   => "text/html",
 ".html"    => "text/html",
 ".htm"     => "text/html",
 ".dtd"     => "text/xml",
 ".xml"     => "text/xml",
 ".css"     => "text/css",
 ".js"      => "text/javascript",
 ".deb"     => "application/x-deb",
 ".php"     => "application/x-httpd-php",
 ""         => "text/plain",
)
static-file.exclude-extensions = (
 ".fcgi",
 ".php",
)
url.access-deny = (
 "~",
 ".ini",
 ".inc",
 ".cfg",
 ".tpl",
 ".bak",
 ".dist",
 ".orig",
 ".htaccess",
 ".htpasswd",
 ".example",
 ".sample",
 ".lang",
)
fastcgi.server = ( ".php" =>
 ( "localhost" => 
 ( 
 "socket" => "/tmp/php-fastcgi.socket",
 "bin-path" => "/usr/bin/php-cgi",
 "broken-scriptfilename" => "enable",
        )
  )
)
EOF

Damit der Lighty nach einem Reboot zur Verfügung steht, erstellen wir den Runlevel

rc-update add lighttpd default

Jetzt können wir endlich den Lighty starten. Achtet bitte auf Fehlermeldungen. Diese sind i.d.R. eindeutig und leicht zu verstehen. Die Logs befinden sich im Verzeichnis '/var/log/lighttpd/'

/etc/init.d/lighttpd start

3.0 Test und Abschluss der Installation

Wir können nun den Lighty und die Konfiguration von PHP testen.

cat > /var/www/domain/htdocs/test.php << "EOF"
<?php
phpinfo()
?>
EOF

Möchtest du Änderungen am PHP vornehmen, die php.ini befindet sich

/etc/php/cgi-php5/php.ini

Ich wünsche nun viel Spaß mit Lighttpd :-)

Zurück zum Index