Install Lighttpd With PHP FPM And MariaDB (LLMP) on Debian 9

Install Lighttpd on Debian 9

Lighttpd is an open-source web server designed for speed-critical environments. It was originally developed as POC (Proof Of Concept) by Jan Kneschke to handle 10K connections in parallel on one server.

With a low memory footprint compared to other webservers, effective management of the CPU-load, and advanced feature sets such as FastCGI, SCGI, Output-Compression, Auth, URL-Rewriting and much more makes Lighttpd the perfect solution for servers suffering load problems.

Lighttpd is licensed under the revised BSD license and runs natively on Linux operating systems as well as Microsoft Windows.

Follow me through the installation of Lighttpd on Debian 9 with PHP (through PHP-FPM) and MariaDB support.

Log in as root account or switch to root user.

$ su

OR

$ sudo su -

Install MariaDB:

First, we will install MariaDB, a fork of MySQL by issuing the following command.

apt-get -y install  mariadb-server

Start MySQL server.

systemctl start mariadb

Set MariaDB service to start automatically during every boot.

systemctl enable mariadb

I recommend you to make MariaDB secure by using the mysql_secure_installation command.

Install Lighttpd:

Latest Lighttpd is available on Debian repository, so, you can install it using the apt-get command.

apt-get -y install lighttpd

Start the Lighttpd service after the installation.

systemctl start lighttpd

Firewall:

Issue the following commands to allow HTTP (80) and HTPPS (443) request through the firewall.

ufw allow 80/tcp
ufw allow 443/tcp
ufw reload

Open a web browser and visit the following URL.

http://your-ip-add-ress

You should get the following page, and this confirms that you have successfully installed Lighttpd on the server.

Install Lighttpd on Debian 9 – Default Page

Auto-start the Lighttpd service at your system start up.

# systemctl enable lighttpd

Install PHP5-FPM:

Now, we will install PHP through PHP-FPM (PHP-FPM (FastCGI Process Manager). PHP-FPM is an alternative PHP FastCGI implementation, and it has some additional features useful for sites of any size, especially busier sites.

apt-get -y install php-fpm php-mysql

Edit php.ini file.

nano /etc/php/7.0/fpm/php.ini

set cgi.fix_pathinfo to 1.

cgi.fix_pathinfo=1

PHP-FPM listens on the UNIX socket /var/run/php7-fpm.sock by default. Edit the file “/etc/php/7.0/fpm/pool.d/www.conf” to make PHP-FPM listens on TCP socket.

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

Change the listen parameter.

FROM:

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

TO:

listen = 127.0.0.1:9000

Restart PHP-FPM service.

systemctl restart php7.0-fpm

Edit 15-fastcg-php.conf file.

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

Look for the below entries and change it.

FROM:

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

TO:

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

Enable FastCGI and FastCGI-PHP modules.

lighty-enable-mod fastcgi
lighty-enable-mod fastcgi-php

Restart Lighttpd service.

systemctl restart lighttpd

PHP-FPM Support on Virtual Host:

Let’s create a name based virtual host on Lighttpd server for the following details.

Server Name : server.itzgeek.local
Document Root : /var/www/html/server.itzgeek.local

Create a configuration file called itzgeek.conf  in /etc/lighttpd/conf-available/.

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

Add the following content.

$HTTP["host"] == "server.itzgeek.local" {   ### Domain URL
server.document-root = "/var/www/html/server.itzgeek.local"   ### Document root
}

Enable the virtual host.

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

Testing PHP-FPM support on Virtual host:

Create the document root directory and log directory.

mkdir /var/www/html/server.itzgeek.local

For testing the PHP-FPM, place a .php file on to the document root of the created virtual host.

nano /var/www/html/server.itzgeek.local/index.php

VI editor will open up a file called index.php. Copy/Paste this line into the index.php file:

<?php phpinfo(); ?>

Set permission.

chown -R www-data:www-data /var/www/html/

Restart the services.

systemctl restart lighttpd
systemctl restart php7.0-fpm

Now open a web browser and type your domain in the web address.

In my case it is,

http://sever.itzgeek.local

the page will look like below:

Install Lighttpd on Debian 9 – PHP-FPM Support

From the above screen shot, PHP is working, and it’s working through FPM/FastCGI, as shown in the Server API line.

Scroll further down to see modules that are already enabled in PHP, including MySQL information.

That’s all!

debian 9lighttpdmariadbmysqlphpweb server
Comments (2)
Add Comment
  • Julian Silverton

    Newby to Lighttpd.
    I am working as root
    I want to host jpg.pics taken by Motion webcam on lighttpd. These photos are saved in a Motion file called var/www/motion.
    How do I set up Lighttpd to host these pics on my LAN?
    Thanks

    • ITzGeek Web

      You update the configuration file

      Change the document root

      /var/www/html/server.itzgeek.local to your directory