DebianDebian BasedTutorials

How To Install Lighttpd with PHP on Debian 11

Install Lighttpd with PHP on Debian 11

In this tutorial, we will show you how to install Lighttpd with PHP on Debian 11. For those of you who didn’t know, Lighttpd (pronounced ”lighty”) is open-source and is a secure, fast, standards-compliant web server designed for speed-critical environments. Lighttpd needs low memory which makes that popular among other web servers. Its small size is 1MB and has low CPU and RAM usage.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Lighttpd with PHP on a Debian 11 (Bullseye).

Prerequisites

  • A server running one of the following operating systems: Debian 10 or Debian 11.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Lighttpd with PHP on Debian 11 Bullseye

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade

Step 2. Installing Lighttpd on Debian 11.

By default, Lighttpd is available on Debian 11 base repository. So, now run the following command below to install the Lighttpd packages on your Debian system:

sudo apt install lighttpd

After successfully installation, enable Lighttpd (to start automatically upon system boot), start, and verify the status using the commands below:

sudo systemctl enable lighttpd
sudo systemctl start lighttpd
sudo systemctl status lighttpd

Step 3. Accessing Lighttpd Web Server.

Once successfully installed, open a web browser on your system and type the server’s IP in the address bar. You will get the default Lighttpd server page:

Install Lighttpd with PHP on Debian 11

Step 4. Installing PHP and PHP-FPM.

Lighttpd web server won’t be usable without PHP FastCGI support. Now we run the following command to install the PHP and PHP-FPM packages to your system:

sudo apt install php php-cgi php-fpm php-mysql

Next, edit the php.ini file and set cgi.fix_pathinfo to 1:

nano /etc/php/7.4/fpm/php.ini

Add the following file:

cgi.fix_pathinfo=1

Save and close the file, then replace the default PHP-CGI configuration and PHP-FPM socket:

nano /etc/php/7.4/fpm/pool.d/www.conf

Find the following line:

listen = /run/php/php7.4-fpm.sock

Now replace with the following line:

listen = 127.0.0.1:9000

Finally, restart the PHP-FPM service to apply the configuration changes:

sudo systemctl restart php7.4-fpm

Step 5. Configure Lighttpd.

Now we edit the Lighttpd configuration file and change it using the Fast CGI:

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

Find the following lines:

"bin-path" => "/usr/bin/php-cgi",
"socket" => "/var/run/lighttpd/php.socket",

Next, replaced them with the following lines:

"host" => "127.0.0.1",
"port" => "9000",

Save and close the file, then restart the PHP-FPM service to apply the configuration:

lighty-enable-mod fastcgi
lighty-enable-mod fastcgi-php
sudo systemctl restart lighttpd

Step 6. Configure Lighttpd Virtual Host.

Now we create a new virtual host file to test PHP with Lighttpd:

nano /etc/lighttpd/conf-available/example.conf

Add the following lines:

$HTTP["host"] == "example.com" {
    server.document-root = "/var/www/html/"
    server.errorlog      = "/var/log/lighttpd/example.com-error.log"
}

Save and close the file then activate the virtual host with the following command below:

ln -s /etc/lighttpd/conf-available/test.conf /etc/lighttpd/conf-enabled/

Then, create a sample index.php file in the Lighttpd document root directory with the command below:

nano /var/www/html/index.php

Add the following line:

<?php
phpinfo();
?>

Save and close the file, also set proper permission and ownership with the following command below:

chown -R www-data:www-data /var/www/html/
chmod -R 755 /var/www/html
sudo systemctl restart lighttpd

Once successfully configure the virtual host, open your web browser and verify your website using the URL http://example.com.

Congratulations! You have successfully installed Lighttpd. Thanks for using this tutorial for installing the latest version of the Lighttpd with PHP on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Lighttpd website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button