• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

CentOS - Installing Lighttpd

Do you have a site that is pushing only static content, a couple of .html or .swf files? Databasing is completely unnecesary for you and Apache seems to be eating alot of unnecessary PIDs and allocating alot of memory. Lighttpd (or more commonly known as Litey) is an ultra light weight and efficient webserver, purpose built to host static .html or download content.

I'll go ahead and walk you through installing this on a CentOS cloud server from a fresh install. Aside from installing it from source, it isn't that scary, we'll need to do a little bit of a dependency hunt, but its covered.




So here we go, here is all the packages that you are going to need to install to get this running for you. Luckily CentOS, my free Redhat styled distro of choice has made the majority of your search easy by the use of Group installs. Is it more secure to install each package you'll need separately and not use the group installs??? Yes it is, but then you have to search through all the dependencies that you'll need by hand as well. That is the next step in this process once you feel comfortable installing and configuring Lighttpd.

Update your base install

 # yum update 

Group installs

There are two Groups that we need to install to complete the Lighttpd install. I also included Editors, just cause I like the functionality of VIM over vi or nano. So the two necessaries are:

  1. Development Tools
  2. Development Libraries
 # yum groupinstall Editors "Development Tools" "Development Libraries" 


This is the only dependency not provided through the above groups. You'll want to install "pcre" and its devel packages as well.

 # yum install pcre-devel pcre 


This section will go through preparing the install area to the actual build.

Where to install

Technically you can install anywhere that you like, I generally will install in a tmp directory inside my home directory, so its easy to know what to delete later.

 # mkdir ~/tmp 

Download and Unpack your package

Download the most recent stable version, at the time of writing this article it was 1.4.22.

# cd ~/tmp/
# wget http://www.lighttpd.net/download/lighttpd-1.4.22.tar.gz 
# tar xzvf lighttpd-1.4.22.tar.gz 
# cd lighttpd-1.4.22/

Configure and Make

If you've never built a package from source, its usually the same steps.

  • Configure the package to your systems specs
 # ./configure 
  • Run Make
 # make 
  • Rune Make Install
 # make install 
  • Confirm it installed
 # which lighttpd 

This command will return a path to the now installed binary for the server


From here we are going to setup Lighttpd to start at boot and work with Virtual Hosts. Easy enough since most of the default settings that we want are assumed, the config file is going to very short compared to something like apache.

Configuration File

  • Config Directory
 # mkdir -p /etc/lighttpd 
  • sample lighttpd.conf

Paste the bellow configurations into lighttpd.conf and edit as necessary to fit your needs.

## Lighttpd Configuration File ##
# Default Document Root
# This is the site that the server will revert to incase of an unknown Virtual Host
server.document-root = "/var/www/servers/example.com" 
# Listening Port
server.port = 80
# Lighttpd User and Group
server.username = "www"
server.groupname = "www"
# Acceptable Mime types
mimetype.assign = (
  ".html" => "text/html", 
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png" 
static-file.exclude-extensions = (".fcgi", ".php", ".rb", "~", ".inc")
index-file.names = ("index.html")
$HTTP["host"] == "subdomain.example.com" {
	server.document-root = "/var/www/servers/subdomain.example.com"

INIT script

# touch /etc/init.d/lighttpd
# chmod a+rx /etc/init.d/lighttpd
# chkconfig --add lighttpd
# chkconfig lighttpd on


  • Copy the bellow contents in /etc/init.d/lighttpd
# lighttpd     Startup script for the lighttpd server
# chkconfig: - 85 15
# description: Lightning fast webserver with light system requirements
# processname: lighttpd
# config: /etc/lighttpd/lighttpd.conf
# config: /etc/sysconfig/lighttpd
# pidfile: /var/run/lighttpd.pid
# Note: pidfile is assumed to be created
# by lighttpd (config: server.pid-file).
# If not, uncomment 'pidof' line.
# Source function library
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/lighttpd ]; then
	. /etc/sysconfig/lighttpd
if [ -z "$LIGHTTPD_CONF_PATH" ]; then
start() {
	echo -n $"Starting $prog: "
	daemon $lighttpd -f $LIGHTTPD_CONF_PATH
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
	return $RETVAL
stop() {
	echo -n $"Stopping $prog: "
	killproc $lighttpd
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
	return $RETVAL
reload() {
	echo -n $"Reloading $prog: "
	killproc $lighttpd -HUP
	return $RETVAL
case "$1" in
		if [ -f /var/lock/subsys/$prog ]; then
		status $lighttpd
		echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
exit $RETVAL


Document Roots and Testing

Certainly you can place the document root where you like, here is how I set it up for this particular config file.

# mkdir -p /var/www/servers/example.com
# mkdir -p /var/www/servers/subdomain.example.com
# echo "test successful" > /var/www/servers/example.com/index.html
# echo "test successful subdomain.example.com" > /var/www/servers/subdomain.example.com/index.html


Start it up

#  /etc/init.d/lighttpd start

© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER