Best Lighttpd Web Server Installation on Debian 12
This tutorial aims to guide you through the Best Lighttpd Web Server Installation on Debian 12 Bookworm from the Command Line. Lighttpd, often referred to as Lighty, stands out as a free, open-source, lightweight, high-speed, and secure web server. It serves as an excellent alternative to Apache and is frequently chosen for high-traffic websites. For those interested, you can also explore Top 5 Alternatives To Apache HTTP Server on Linux.
Follow the steps below on the website to begin your journey with the Best Lighttpd Web Server Installation on Debian 12 with MariaDB and PHP.
Steps To Best Lighttpd Web Server Installation on Debian 12 From Command Line
Before commencing the Best Lighttpd Web Server Installation on Debian 12, ensure you have access to your server as a non-root user with sudo privileges. Consult the guide on Initial Server Setup with Debian 12 Bookworm for assistance.
You will also need a domain name pointed to your server’s IP address. The subsequent steps will guide you through the process of installing and configuring Lighttpd.
Step 1 – Install Lighttpd Web Server on Debian 12 Bookworm
Debian 12 comes pre-packaged with Lighttpd 1.4.69. Kick off the Best Lighttpd Web Server Installation on Debian 12 by updating the system packages:
sudo apt update
Next, install Lighty on Debian 12 using the following command:
sudo apt install lighttpd -y
To verify the installed Lighttpd version, execute:
lighttpd -v
**Output**
lighttpd/1.4.69 (ssl) - a light and fast webserver
Step 2 – Start and Enable Lighttpd Service on Debian12
This step in the Best Lighttpd Web Server Installation on Debian 12 involves starting the Lighttpd service:
sudo systemctl start lighttpd
Then, enable the service to automatically start at boot:
sudo systemctl enable lighttpd
Confirm the successful installation and that Lighttpd is active and running:
sudo systemctl status lighttpd
The output should resemble:
**Output**
● lighttpd.service - Lighttpd Daemon
Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; preset: ena>
Active: **active** (**running**) since Sun 2023-06-18 05:23:59 EDT; 2min 44s ago
Main PID: 3379 (lighttpd)
Tasks: 1 (limit: 4653)
Memory: 808.0K
CPU: 362ms
CGroup: /system.slice/lighttpd.service
Step 3 – Install MariaDB Support for Lighttpd on Debian 12
Enhance your Best Lighttpd Web Server Installation on Debian 12 by adding MariaDB support. Install MariaDB server and client:
sudo apt install mariadb-server mariadb-client -y
Confirm the MariaDB installation by checking its version:
mariadb --version
**Output**
mariadb Ver 15.1 Distrib 10.11.3-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
Start and enable the MariaDB service:
# sudo systemctl start mariadb
# sudo systemctl enable mariadb
Verify that MariaDB is active and running:
sudo systemctl status mariadb
**Output**
● mariadb.service - MariaDB 10.11.3 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enab>
Active: **active** (**running**) since Sun 2023-06-18 05:30:52 EDT; 47s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 5083 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 14 (limit: 4653)
Memory: 174.9M
CPU: 769ms
CGroup: /system.slice/mariadb.service
Secure your MariaDB installation by running the security script:
sudo mysql_secure_installation
**Output**
Enter current password for root (enter for none):
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] **n**
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] **Y**
New password:
Re-enter new password:
Remove anonymous users? [Y/n] **Y**
Disallow root login remotely? [Y/n] **Y**
Remove test database and access to it? [Y/n] **Y**
Reload privilege tables now? [Y/n] **Y**
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Access the MariaDB shell:
sudo mysql -u root -p
**Output**
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 39
Server version: 10.11.3-MariaDB-1 Debian 12
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
**MariaDB [(none)]>**
Step 4 – Install PHP and PHP-FPM with FastCGI on Debian 12
Enable PHP-FPM with FastCGI support by installing PHP and necessary extensions:
sudo apt install php php-cgi php-fpm php-mysql -y
Verify the PHP installation:
php --version
**Output**
PHP 8.2.7 (cli) (built: Jun 9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies
Edit the php.ini
file and set cgi.fix_pathinfo
to 1
:
sudo vi /etc/php/8.2/fpm/php.ini
Find and uncomment the following line, changing its value:
cgi.fix_pathinfo=1
Save and close the file.
Configure the PHP-FPM pool to listen to the TCP socket by editing /etc/php/8.2/fpm/pool.d/www.conf
:
sudo vi /etc/php/8.2/fpm/pool.d/www.conf
Find:
listen = /run/php/php8.2-fpm.sock
Replace with:
listen = 127.0.0.1:9000
Save and close the file.
Restart the PHP-FPM service:
sudo systemctl restart php8.2-fpm
Modify the 15-fastcgi-php.conf
file:
sudo vi /etc/lighttpd/conf-available/15-fastcgi-php.conf
Find:
fastcgi.server += ( ".php" =>
((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/run/lighttpd/php.socket",
...
))
)
Replace with:
"host" => "127.0.0.1",
"port" => "9000",
Save and close the file.
Enable FastCGI and FastCGI-PHP modules:
# lighty-enable-mod fastcgi
# lighty-enable-mod fastcgi-php
Restart the Lighttpd service:
sudo systemctl restart lighttpd
Step 5 – Create Lighttpd Virtual Host on Debian 12
Create a new virtual host file:
sudo vi /etc/lighttpd/conf-available/<example.com>.conf
Add the following content:
$HTTP["host"] == "www.<example.com>" {
server.document-root = "/var/www/html/"
server.errorlog = "/var/log/lighttpd/<example.com>-error.log"
}
Save and close the file.
Enable the Virtual host:
sudo ln -s /etc/lighttpd/conf-available/<example.com>.conf /etc/lighttpd/conf-enabled/
Create a sample index.php
file:
sudo vi /var/www/html/index.php
Add:
<?php
phpinfo();
?>
Save and close the file.
Change the ownership of the Lighttpd document root directory:
sudo chown -R www-data:www-data /var/www/html/
Restart the Lighttpd service:
sudo systemctl restart lighttpd
Step 6 – Test Lighttpd Installation and Configuration
Access your domain name or server’s IP address in a web browser:
http://<domain-name>
Or
http://<server-ip>
You should see information about PHP, PHP-FPM, and MySQL, along with enabled modules.

For further details, consult the Lighttpd Documentation page.
Conclusion
You have now successfully completed the Best Lighttpd Web Server Installation on Debian 12 with MariaDB support and enabled PHP-FPM with FastCGI support. You have also learned to create a Lighttpd virtual host file.
Alternative Solutions for Serving Dynamic Content with Lighttpd
While the above guide utilizes PHP-FPM with FastCGI, other approaches exist to serve dynamic content with Lighttpd. Here are two alternative solutions:
1. Using CGI (Common Gateway Interface):
CGI is a simpler, albeit less performant, method for executing server-side scripts. Instead of running as a persistent process like PHP-FPM, CGI scripts are invoked for each request.
- Explanation: Lighttpd can be configured to execute scripts (e.g., Perl, Python, or PHP) as CGI programs. When a request arrives for a CGI script, Lighttpd spawns a new process to execute the script. The script’s output is then sent back to the client.
- Drawbacks: The primary drawback is the overhead of creating a new process for each request, which can significantly impact performance, especially under high load.
- Configuration: To enable CGI, you would need to configure Lighttpd to recognize specific file extensions (e.g.,
.cgi
,.pl
,.py
) as CGI scripts and specify the path to the interpreter. You’d also need to ensure the CGI scripts have execute permissions.
Here’s a sample snippet of Lighttpd configuration (lighttpd.conf):
server.modules += ( "mod_cgi" )
cgi.assign = (
".pl" => "/usr/bin/perl",
".cgi" => "/usr/bin/perl",
".py" => "/usr/bin/python3"
)
Create a simple Python CGI script (e.g., test.py
)
#!/usr/bin/python3
print("Content-Type: text/htmln")
print("<html><body><h1>Hello from Python CGI!</h1></body></html>")
Remember to make the script executable: chmod +x test.py
2. Using a Reverse Proxy to Another Application Server:
This approach involves running your dynamic application (e.g., a Node.js application, a Python application using Flask or Django) on a separate application server and configuring Lighttpd as a reverse proxy.
- Explanation: Lighttpd acts as a front-end, receiving client requests and forwarding them to the application server. The application server processes the request and sends the response back to Lighttpd, which then relays it to the client.
- Benefits: This approach offers several benefits, including improved scalability, flexibility, and security. It allows you to choose the most appropriate application server for your specific needs and isolate your application from the web server.
- Configuration: You would configure Lighttpd to forward requests for specific URLs or paths to the application server’s address and port.
Here’s an example configuration in lighttpd.conf
:
$HTTP["url"] =~ "^/app/" {
proxy.server = ( "" => ( (
"host" => "127.0.0.1",
"port" => 3000
) ) )
}
In this example, any request starting with /app/
will be proxied to an application server running on 127.0.0.1:3000
.
This approach gives you flexibility. You could run a Node.js application using Express.js, for example:
// Example Node.js Express app (app.js)
const express = require('express');
const app = express();
const port = 3000;
app.get('/app', (req, res) => {
res.send('Hello from Node.js Express!');
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});
//Run this app with node app.js
By choosing one of these alternate solutions, you can tailor your web server setup to your exact needs and create the Best Lighttpd Web Server Installation on Debian 12 for your project.