Install Lighttpd on Debian 11

This article will take you through how to install Lighttpd on Debian 11. Lighttpd, pronounced “lighty,” is an open-source web server designed for environments where performance is crucial while remaining secure and customizable. Its features include FastCGI, CGI, basic and digest HTTP authentication, output compression, and URL rewriting.

How to Install Lighttpd on Debian 11

  • Update your packages using the command below.
sudo apt update
  • Next, install Lighttpd using the following command.
sudo apt install lighttpd -y

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  lighttpd-mod-deflate lighttpd-mod-openssl spawn-fcgi
Suggested packages:
  rrdtool php-cgi php-fpm apache2-utils lighttpd-doc
  lighttpd-mod-authn-gssapi lighttpd-mod-authn-pam
  lighttpd-mod-authn-sasl lighttpd-mod-geoip lighttpd-mod-maxminddb
  lighttpd-mod-trigger-b4-dl lighttpd-mod-vhostdb-pgsql
  lighttpd-mod-webdav lighttpd-modules-dbi lighttpd-modules-ldap
  lighttpd-modules-lua lighttpd-modules-mysql
The following NEW packages will be installed:
  lighttpd lighttpd-mod-deflate lighttpd-mod-openssl spawn-fcgi
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 402 kB of archives.
After this operation, 1,417 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 lighttpd amd64 1.4.59-1+deb11u1 [359 kB]
Get:2 http://deb.debian.org/debian bullseye/main amd64 lighttpd-mod-deflate amd64 1.4.59-1+deb11u1 [9,704 B]
Get:3 http://deb.debian.org/debian bullseye/main amd64 lighttpd-mod-openssl amd64 1.4.59-1+deb11u1 [19.2 kB]
Get:4 http://deb.debian.org/debian bullseye/main amd64 spawn-fcgi amd64 1.6.4-2 [14.8 kB]
Fetched 402 kB in 3s (150 kB/s)       
Selecting previously unselected package lighttpd.
(Reading database ... 141232 files and directories currently installed.)
Preparing to unpack .../lighttpd_1.4.59-1+deb11u1_amd64.deb ...
Unpacking lighttpd (1.4.59-1+deb11u1) ...
Selecting previously unselected package lighttpd-mod-deflate.
Preparing to unpack .../lighttpd-mod-deflate_1.4.59-1+deb11u1_amd64.deb ...
Unpacking lighttpd-mod-deflate (1.4.59-1+deb11u1) ...
Selecting previously unselected package lighttpd-mod-openssl.
Preparing to unpack .../lighttpd-mod-openssl_1.4.59-1+deb11u1_amd64.deb ...
Unpacking lighttpd-mod-openssl (1.4.59-1+deb11u1) ...
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+deb11u1) ...
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+deb11u1) ...
Setting up spawn-fcgi (1.6.4-2) ...
Setting up lighttpd-mod-deflate (1.4.59-1+deb11u1) ...
Processing triggers for man-db (2.9.4-2) ...
  • Start Lighttpd.
sudo systemctl start lighttpd
  • Then enable Lighttpd to start on boot.
sudo systemctl enable lighttpd
  • Check Lighttpd status.
systemctl status lighttpd

Sample output

● lighttpd.service - Lighttpd Daemon
     Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-07-06 05:11:22 EDT; 53s ago
   Main PID: 30849 (lighttpd)
      Tasks: 1 (limit: 4623)
     Memory: 876.0K
        CPU: 458ms
     CGroup: /system.slice/lighttpd.service
             └─30849 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
  • In case you are using a firewall allow the ports below.
sudo ufw allow 80
sudo ufw allow 443

Install PHP on Debian 11

  • Install PHP with some commonly used extensions using the command below.
sudo apt install php php-cgi php-fpm php-mysql -y

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  php-common php7.4 php7.4-cgi php7.4-cli php7.4-common php7.4-fpm
  php7.4-json php7.4-mysql php7.4-opcache php7.4-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  php php-cgi php-common php-fpm php-mysql php7.4 php7.4-cgi
  php7.4-cli php7.4-common php7.4-fpm php7.4-json php7.4-mysql
  php7.4-opcache php7.4-readline
0 upgraded, 14 newly installed, 0 to remove and 40 not upgraded.
Need to get 5,721 kB of archives.
After this operation, 28.0 MB of additional disk space will be used.
Get:1 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-common amd64 7.4.30-1+deb11u1 [1,023 kB]
Get:2 http://deb.debian.org/debian bullseye/main amd64 php-common all 2:76 [15.6 kB]
Get:3 http://deb.debian.org/debian bullseye/main amd64 php all 2:7.4+76 [6,340 B]
Get:4 http://deb.debian.org/debian bullseye/main amd64 php-cgi all 2:7.4+76 [6,852 B]
Get:5 http://deb.debian.org/debian bullseye/main amd64 php-fpm all 2:7.4+76 [6,424 B]
Get:6 http://deb.debian.org/debian bullseye/main amd64 php-mysql all 2:7.4+76 [6,360 B]
Get:7 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-json amd64 7.4.30-1+deb11u1 [19.3 kB]
Get:8 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-opcache amd64 7.4.30-1+deb11u1 [197 kB]
Get:9 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-readline amd64 7.4.30-1+deb11u1 [12.3 kB]
Get:10 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-cli amd64 7.4.30-1+deb11u1 [1,428 kB]
Get:11 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-fpm amd64 7.4.30-1+deb11u1 [1,439 kB]
Get:12 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-cgi amd64 7.4.30-1+deb11u1 [1,389 kB]
Get:13 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4 all 7.4.30-1+deb11u1 [49.8 kB]
Get:14 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-mysql amd64 7.4.30-1+deb11u1 [121 kB]
Fetched 5,721 kB in 20s (290 kB/s)                                  
Selecting previously unselected package php-common.
(Reading database ... 141348 files and directories currently installed.)
Preparing to unpack .../00-php-common_2%3a76_all.deb ...
Unpacking php-common (2:76) ...
Selecting previously unselected package php7.4-common.
Preparing to unpack .../01-php7.4-common_7.4.30-1+deb11u1_amd64.deb .
..
Unpacking php7.4-common (7.4.30-1+deb11u1) ...
Selecting previously unselected package php7.4-json.
Preparing to unpack .../02-php7.4-json_7.4.30-1+deb11u1_amd64.deb ...
Unpacking php7.4-json (7.4.30-1+deb11u1) ...
Selecting previously unselected package php7.4-opcache.
Preparing to unpack .../03-php7.4-opcache_7.4.30-1+deb11u1_amd64.deb 
...
Unpacking php7.4-opcache (7.4.30-1+deb11u1) ...
Selecting previously unselected package php7.4-readline.
Preparing to unpack .../04-php7.4-readline_7.4.30-1+deb11u1_amd64.deb
 ...
  • Check the version of PHP installed.
php -v

Configure PHP-FPM and FastCGI on Debian 11

  • Uncomment the line cgi.fix_pathinfo=1 in the file below.
sudo nano /etc/php/7.4/fpm/php.ini
  • Next, configure PHP-FPM in the file below.
sudo nano /etc/php/7.4/fpm/pool.d/www.conf
  • Search for the line below.
listen = /run/php/php*-fpm.sock
  • Then replace it with the following line.
listen = 127.0.0.1:9000

Save(ctrl+s) and close(ctrl+x) the file.

  • Next, enable FastCGI. Open the config file below.
sudo nano /etc/lighttpd/conf-available/15-fastcgi-php.conf
  • Replace the line below.
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/var/run/lighttpd/php.socket",
  • With the following lines.
"host" => "127.0.0.1",
"port" => "9000",
  • Enable the FastCGI module using the following commands.
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
  • Let’s test if PHP is working by creating a test file.
sudo nano /var/www/html/index.php
  • Paste the code below inside the created file.
<?php
 phpinfo();
 ?>
  • Give Lighttpd proper permissions.
sudo chown -R www-data:www-data /var/www/html/ 
sudo chmod -R 755 /var/www/html/
  • Next, restart the Lighttpd server.
sudo /etc/init.d/lighttpd restart 
  • Enter your server IP or domain name to test if PHP works with Lighttpd. e.g. 127.0.0.1 or localhost.
Install Lighttpd on Debian 11
Install Lighttpd on Debian 11

Install MariaDB on Debian 11

  • Run the command below to Install MariaDB.
sudo apt install mariadb-server
  • Secure MariaDB.
sudo mysql_secure_installation

Sample output

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
  • To log in to MariaDB, run the following command.
sudo mysql -u root -p
  • It’s a wrap! You have reached the end of our guide. We have gone through how to install Lighttpd on Debian 11. Cheers!

Read more on Lighttpd Documentation

Other Tutorials

Install WordPress with Apache on OpenSUSE

Install phpMyAdmin with Apache on Debian 11

Install phpMyAdmin with Apache on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment