How to install lighttpd from source code
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..
1 2 |
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
1 2 |
apt update apt -y install build-essential wget |
Next, we will download and install lighttpd, you can get the latest version download link from
1 2 3 4 5 6 7 8 |
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
1 |
configure: error: pcre2-config not found, install the pcre2-devel package or build with --without-pcre2 |
install pcre2 devel package
RHEL
1 |
dnf install -y pcre2-devel |
For Ubuntu/Debian
1 |
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
1 |
apt install -y zlib1g-dev |
Create User
Let’s create a user for running lighttpd
1 2 |
groupadd lighttpd adduser -m -g lighttpd -d /var/www -s /sbin/nologin lighttpd |
For Ubuntu/Debian
1 |
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
1 2 3 |
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
1 2 |
mkdir /var/log/lighttpd chown -R lighttpd:lighttpd /var/log/lighttpd |
Copy service files
1 2 |
cp doc/systemd/lighttpd.service /usr/lib/systemd/system/ cp doc/systemd/lighttpd.socket /usr/lib/systemd/system/ |
Update configuration files
Edit
1 |
vi /etc/lighttpd/modules.conf |
Find
1 |
server.modules += ( "mod_Foo" ) |
Comment the line.
Edit /etc/lighttpd/lighttpd.conf
1 |
vi /etc/lighttpd/lighttpd.conf |
Find
1 |
server.use-ipv6 = "enable" |
Replace with
1 |
server.use-ipv6 = "disable" |
Update server document root as needed
1 2 |
var.server_root = "/var/www" server.document-root = server_root + "/html" |
Starting lighttpd
Verify configuration file has now errors
1 |
/usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf |
Run lighttpd manually
1 |
/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf |
You can enable/start lighttpd with
1 2 3 |
systemctl enable lighttpd systemctl start lighttpd systemctl status lighttpd |
back to lighttpd