CentOS – Installing Lighttpd

  Uncategorized

Prerequisites

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"

PCRE

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

Install

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

Setup

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
 
#!/bin/sh
#
# 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
fi
 
if [ -z "$LIGHTTPD_CONF_PATH" ]; then
	LIGHTTPD_CONF_PATH="/etc/lighttpd/lighttpd.conf"
fi
 
prog="lighttpd"
lighttpd="/usr/local/sbin/lighttpd"
RETVAL=0
 
start() {
	echo -n $"Starting $prog: "
	daemon $lighttpd -f $LIGHTTPD_CONF_PATH
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
	return $RETVAL
}
 
stop() {
	echo -n $"Stopping $prog: "
	killproc $lighttpd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
	return $RETVAL
}
 
reload() {
	echo -n $"Reloading $prog: "
	killproc $lighttpd -HUP
	RETVAL=$?
	echo
	return $RETVAL
}
 
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	condrestart)
		if [ -f /var/lock/subsys/$prog ]; then
			stop
			start
		fi
		;;
	reload)
		reload
		;;
	status)
		status $lighttpd
		RETVAL=$?
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
		RETVAL=1
esac
 
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

Visits: 57

LEAVE A COMMENT

What is the capital of Egypt? ( Cairo )