Install the require RPMs (php, php-mysql, php-eAccelerator). For Fedora, use yum (lighttpd and lighttpd-fastcgi). For CentOS and other distros that do not include lighttpd in their repository, use DAG repository
Find out the path to php-cgi and whether it supports fastcgi (should show cgi-fcgi)
Configure a light weight lighttpd:
server.modules = (“mod_fastcgi”)
server.document-root = “/home/www/”
server.max-keep-alive-requests = 0
server.max-fds = 2048
server.port = 80
server.errorlog = “/var/log/lighttpd/error_log”
server.tag = “lighttpd”
server.username = “lighttpd”
server.groupname = “lighttpd”
server.pid-file = “/var/run/lighttpd.pid”
#### fastcgi module
fastcgi.server = (“.php”=>(“localhost”=>(“socket”=>”/tmp/php-fastcgi.socket”,”bin-path”=>”/usr/bin/php-cgi”)))
# files to check for if …/ is requested
index-file.names = (“index.php”,”index.html”,”index.htm”,”default.htm”)
# which extensions should not be handle via static-file transfer
# .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
static-file.exclude-extensions = ( “.php”, “.pl”, “.fcgi” )
# mimetype mapping
mimetype.assign = (
“.rpm” => “application/x-rpm”,
“.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”,
“.gz” => “application/x-gzip”,
“.pac” => “application/x-ns-proxy-autoconfig”,
“.swf” => “application/x-shockwave-flash”,
“.tar.gz” => “application/x-tgz”,
“.tgz” => “application/x-tgz”,
“.tar” => “application/x-tar”,
“.zip” => “application/zip”,
“.mp3” => “audio/mpeg”,
“.m3u” => “audio/x-mpegurl”,
“.wma” => “audio/x-ms-wma”,
“.wax” => “audio/x-ms-wax”,
“.ogg” => “application/ogg”,
“.wav” => “audio/x-wav”,
“.gif” => “image/gif”,
“.jpg” => “image/jpeg”,
“.jpeg” => “image/jpeg”,
“.png” => “image/png”,
“.xbm” => “image/x-xbitmap”,
“.xpm” => “image/x-xpixmap”,
“.xwd” => “image/x-xwindowdump”,
“.css” => “text/css”,
“.html” => “text/html”,
“.htm” => “text/html”,
“.js” => “text/javascript”,
“.asc” => “text/plain”,
“.c” => “text/plain”,
“.cpp” => “text/plain”,
“.log” => “text/plain”,
“.conf” => “text/plain”,
“.text” => “text/plain”,
“.txt” => “text/plain”,
“.dtd” => “text/xml”,
“.xml” => “text/xml”,
“.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”,
“.bz2” => “application/x-bzip”,
“.tbz” => “application/x-bzip-compressed-tar”,
“.tar.bz2” => “application/x-bzip-compressed-tar”
)
Might need to switch from httpd to lighttpd
# switch from httpd to lighttpd service httpd stop service lighttpd start chkconfig --list httpd chkconfig lighttpd on chkconfig httpd off chkconfig --list httpd chkconfig --list lighttpd
Can also run both httpd and lighttpd together on the same server (use two different ports, eg: 80 & 81, don’t forget to open the new port in the firewall) for testing/benchmarking or development purposes.
Initial benchmark: a 10-15% improvement on serving dynamic PHP/MySQL pages. Static files are supposed to be much faster. lighttpd is very stable (loadavg is maintained at about 3-4) with higher concurrency levels while Apache might increase loadavg to over 10+
Great kudos to the lighttpd developers for bringing us a fast, light webserver. Fly Light!
Leave a Reply