Lighttpd is a secure, fast, compliant, and very flexible web server that has been optimized for high-performance environments. In this post, we will be installing Lighttpd by compiling the source code.
To install lighttpd from the source, first, let’s install the requirements
For RHEL, CentOS, AlmaLinux, etc..
dnf -y install wget
dnf -y group install 'Development Tools'
Use yum instead of dnf if you are using an older version, for example, CentOS 7
For Ubuntu/Debian
apt update
apt -y install build-essential wget
Next, we will download and install lighttpd, you can get the latest version download link from
https://www.lighttpd.net/
cd /usr/local/src
wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.64.tar.gz
tar -xvf lighttpd-1.4.64.tar.gz
cd lighttpd-1.4.64
make clean && make distclean
./configure --prefix=/usr --with-fam
make
make install
If you get error
configure: error: pcre2-config not found, install the pcre2-devel package or build with --without-pcre2
install pcre2 devel package
RHEL
dnf install -y pcre2-devel
For Ubuntu/Debian
apt install -y libpcre2-dev
If you get error related to zlib “configure: error: zlib headers not found, install them or build without –with-zlib”, install
For Ubuntu/Debian
apt install -y zlib1g-dev
Create User
Let’s create a user for running lighttpd
groupadd lighttpd
adduser -m -g lighttpd -d /var/www -s /sbin/nologin lighttpd
For Ubuntu/Debian
useradd -m -d /var/www -s /sbin/nologin lighttpd
Instead of creating a new user, you can also use user nobody on RHEL based distros, www-data on Ubuntu.
Install configuration files
To setup default lighttpd.conf file, run
install -Dp ./doc/config/lighttpd.conf /etc/lighttpd/lighttpd.conf
cp -R doc/config/conf.d/ /etc/lighttpd/
cp doc/config/conf.d/mod.template /etc/lighttpd/modules.conf
Create a directory for log files
mkdir /var/log/lighttpd
chown -R lighttpd:lighttpd /var/log/lighttpd
Copy service files
cp doc/systemd/lighttpd.service /usr/lib/systemd/system/
cp doc/systemd/lighttpd.socket /usr/lib/systemd/system/
Update configuration files
Edit
vi /etc/lighttpd/modules.conf
Find
server.modules += ( "mod_Foo" )
Comment the line.
Edit /etc/lighttpd/lighttpd.conf
vi /etc/lighttpd/lighttpd.conf
Find
server.use-ipv6 = "enable"
Replace with
server.use-ipv6 = "disable"
Update server document root as needed
var.server_root = "/var/www"
server.document-root = server_root + "/html"
Starting lighttpd
Verify configuration file has now errors
/usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf
Run lighttpd manually
/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
You can enable/start lighttpd with
systemctl enable lighttpd
systemctl start lighttpd
systemctl status lighttpd
back to lighttpd