How to install lighttpd on Debian 11 "Bullseye"

Endrit Qerreti

Endrit Qerreti

lighttpd is an open source web server that you can use on your server to host websites. lighttpd supports CGI, FastCGI and SCGI.

If you are looking for a web server that it's not heavy on the server, lighttpd might be what you are looking for. Not only it's fast and lightweight, but it also supports all major programming languages such as : PHP, Python, Perl and Lua.

In this tutorial, you will learn how to install lighttpd on Debian 11 "Bullseye" via a few steps.

Step 1 - Update your server

It is important to make sure that your server is updated, run the command below to update any old packages that your system might have. After updating, move to the next step.

sudo apt update

Step 2 - Install lighttpd

Once you have updated your server, install lighttpd by running the command below.

sudo apt install lighttpd

You'll be asked to enter your user's password, authenticate to your account and press enter to begin the installation of lighttpd.

The output should look like this

Unpacking lighttpd-mod-deflate (1.4.59-1+deb11u2) ...
Selecting previously unselected package lighttpd-mod-openssl.
Preparing to unpack .../lighttpd-mod-openssl_1.4.59-1+deb11u2_amd64.
deb ...
Unpacking lighttpd-mod-openssl (1.4.59-1+deb11u2) ...
Selecting previously unselected package spawn-fcgi.
Preparing to unpack .../spawn-fcgi_1.6.4-2_amd64.deb ...
Unpacking spawn-fcgi (1.6.4-2) ...
Setting up lighttpd (1.4.59-1+deb11u2) ...
Created symlink /etc/systemd/system/multi-user.target.wants/lighttpd
.service → /lib/systemd/system/lighttpd.service.
Setting up lighttpd-mod-openssl (1.4.59-1+deb11u2) ...
Setting up spawn-fcgi (1.6.4-2) ...
Setting up lighttpd-mod-deflate (1.4.59-1+deb11u2) ...
Processing triggers for man-db (2.9.4-2) ...

This means lighttpd was installed on your system.

Step 3 - Install PHP and MySQL

1.First you need to download the repository with wget

wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -

2.Next, add the repository to your system

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list

3.Once you have downloaded the repository key, and added the sury repository on your system, proceed to update your system

sudo apt update

4. Install php8.2-fpm

sudo apt install php8.2-fpm php8.2-mysql

5.Verify that php got installed

php -v

Output

owlhowto@debian:~$ php -v
PHP 8.2.6 (cli) (built: May 12 2023 07:48:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.6, Copyright (c), by Zend Technologies

6. Configure PHP-FPM

Now you need to make the necessary changes to the php.ini file which is located at /etc/php/8.2/fpm/php.ini. Open this file with any text editor

sudo nano /etc/php/8.2/fpm/php.ini

And look for the line cgi.fix_pathinfo=1, once you find this line, you need to uncomment it, in order to enable it.

7. After configuring fpm, you need to configure 15-fastcgi-php-fpm.conf as this file it's not configured by default.

Open 15-fastcgi-php-fpm.conf with a text editor

sudo nano /etc/lighttpd/conf-available/15-fastcgi-php-fpm.conf

Next, delete the old configuration, and paste the following code to your file

fastcgi.server += ( ".php" =>
        ((
                "socket" => "/run/php/php8.2-fpm.sock",
                "broken-scriptfilename" => "enable"
        ))
)

Make sure to save changes after, press CTRL + X and confirm by pressing the Y key

8. Enable FastCGI config

Now you need to enable the fastcgi configuration, to do so run the commands below

sudo lighttpd-enable-mod fastcgi

Output

owlhowto@debian:~$ sudo lighttpd-enable-mod fastcgi
Enabling fastcgi: ok
Run "service lighttpd force-reload" to enable changes

sudo lighttpd-enable-mod fastcgi-php

Output

owlhowto@debian:~$ sudo lighttpd-enable-mod fastcgi-php
Enabling fastcgi-php: ok
Run "service lighttpd force-reload" to enable changes

9. Reload to enable the new configuration

sudo service lighttpd force-reload

Step 4 - Setup lightttpd configuration

The configuration file lighttpd.conf is the file that contains the configurations for lighttpd, in this file you can set your own configurations. This file is located on /etc/lighttpd/, you can edit the config file easily with any text editor.

sudo nano /etc/lighttpd/lighttpd.conf

Step 5 - enable lighttpd

To make sure that lighttpd process will start when you reboot your server, you need to enable the process by using the systemctl command

systemctl enable lighttpd

Now lighttpd's process will start automatically once your server boots up.

One you execute the command above, you will get prompted to enter your root password, enter the password and click authenticate.

Step 6 - Manage lighttpd

Below we have added the most useful commands that you should know when it comes to managing lighttpd process.

Check lighttpd process status

To check lighttpd process if it's running or not, run the command below

systemctl status lighttpd

Start lighttpd

To start lighttpd process, run the command below

systemctl start lighttpd

Restart lighttpd

To restart lighttpd proces, run the command below

systemctl restart lighttpd

Stop lighttpd

To stop lighttpd process, run the command below

systemctl stop lighttpd

Step 7 - Setup your site

lighttpd uses /var/www/html as the default document root path. This is the path where you need to upload your php code. If you want to change this path, you can define a new one on the config file lighttpd.conf, and then use the new path.

Once you upload your php files, check if they got uploaded successfully. Navigate to your localhost IP with your browser, and you should see your site. If you don't remember your IP, you can find it with

ip a

Look for the inet, the ip should look like this :  10.0.2.15/24, in our case our IP is 10.0.2.15

Conclusion

In this tutorial, you learned how to install lighttpd on Debian 11 "Bullseye". Even though lighttpd doesn't have the same popularity and support as nginx, it is still a good alternative to use when it comes to choosing a web server.