How to install Lighttpd and PHP 8 on Debian Bullseye

7249
Share:
how-to-install-lighttpd-and-php-8-on-debian-bullseye

Lighttpd is a secure, fast, standards-compliant web server designed for speed-critical environments. This tutorial will show how we can install Lighttpd web server on an Debian Bullseye server with PHP 8 module through PHP-FPM. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. In this tutorial we'll use PHP-FPM instead of Lighttpd's spawn-fcgi.

In this tutorial I use the hostname kecoak with the IP address 10.10.10.228. You may have different settings, so you have to replace them where appropriate.

Getting Started

As usual, before proceed with actual installation, make sure that your system packages are up-to-date. Run the commands below to perform system package update and upgrade.

$ sudo apt update
$ sudo apt upgrade

Now we're ready to proceed with installation.

Lighttpd Installation

After the system is ready, we'll continue with Lighttpd installation:

$ sudo apt install lighttpd

When the installation process is done, open your web browser and go to http://10.10.10.228/index.lighttpd.html (your IP might differs). You should see Lighttpd welcome page like below:

Lighttpd Welcome Page

Lighttpd’s default document root is /var/www/html on Debian, and the configuration file is /etc/lighttpd/lighttpd.conf. Additional configurations are stored in files in the /etc/lighttpd/conf-available directory – these configurations can be enabled with the lighttpd-enable-mod command which creates a symlink from the /etc/lighttpd/conf-enabled directory to the appropriate configuration file in /etc/lighttpd/conf-available. You can disable configurations with the lighttpd-disable-mod command.

PHP 8 Installation

Next, we'll continue with PHP 8 installation. Back to terminal, enter this command:

$ sudo apt install php8.0-fpm

PHP-FPM is a daemon process (with the init script php8.0-fpm) that runs a FastCGI server on the socket /var/run/php/php8.0-fpm.sock.

Lighttpd PHP-FPM configuration

To enable PHP8 in Lighttpd, we must modify /etc/php/8.0/fpm/php.ini and uncomment the line cgi.fix_pathinfo=1. In my php.ini file, I found it on line 807. To uncomment, just remove the semicolon in the beginning.

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=1

Next, we need to adjust the file /etc/lighttpd/conf-available/15-fastcgi-php-fpm.conf with correct value.

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

After finished editing, save the file and then enable it in Lighttpd.

$ cd /etc/lighttpd/conf-available/
$ sudo lighttpd-enable-mod fastcgi-php-fpm

We need to reload Lighttpd so it load our new configuration.

$ sudo service lighttpd force-reload

Verify Installation

Let's verify our PHP installation using Lighttpd web server. Create a new file: /var/www/html/index.php

<?php
phpinfo();
?>

Save the file and then open this URL in web browser: http://10.10.10.228/index.php. You should see something like this:

phpinfo() Page

Final Words

I hope that you now know how to install PHP 8 and Lighttpd Web Server on Debian Bullseye. If you run into any issues or have any feedback feel free to drop a comment below.

Tags PHP Linux
Share:

0 comment

Leave a reply

Your email address will not be published. Required fields are marked *