Build Lighttpd server in Raspberry Pi

Posted May 27, 20202 min read

Lighttpd, like Ngnix, is designed to run on devices with low memory and low CPU load. They are all very suitable for running on the Raspberry Pi.

This article will explain how to run the basic configuration of Lighttpd on the Raspberry Pi and how to use it with PHP-FRM.

Install Lighthttpd

  1. First, we first ensure that our Raspberry Pi software is up to date:

    $sudo apt-get update
    $sudo apt-get upgrade

  2. We also need to remove Apache2, if your system has been removed, you can skip this step.

    $sudo apt-get remove apache2

  3. Next, you can install Lighttpd.

    $sudo apt-get install lighttpd

  4. After Lighttpd has been installed correctly, we need to first determine whether it is working properly. Use any browser and enter the LAN address of the Raspberry Pi to access. If you don't know the LAN address, you can use the following command to get it:

    $hostname -I

You will see the following page:

  1. If you think this page is too ugly, you can modify it yourself:

    $sudo vim /var/www/html/index.html

Install LighttpdPHP

  1. In this tutorial, we will use PHP-FPM, the version is PHP7. Why use PHP7 instead of PHP5? Because PHP7 is updated, performance is better and memory management is better.

  2. We can install PHP-FPM in the following ways:

    $sudo apt-get install php7.0-fpm

Configure Lighthttpd

  1. After installing PHP-FPM, we need to run the following two commands to create two hyperlinks. When Lighttpd is running, it will read the two settings for PHP.

    $sudo lighttpd-enable-mod fastcgi
    $sudo lighttpd-enable-mod fastcgi-php

  2. lighttpd runs PHP-CGI instead of PHP-FPM by default, we can run PHP-FPM by modifying the following configuration file:

    $sudo vim /etc/lighttpd/conf-available/15-fastcgi-php.conf

Modify the above configuration file as follows:

# /usr/share/doc/lighttpd/fastcgi.txt.gz

## Start an FastCGI server for php(needs the php5-cgi package)
fastcgi.server + =(".php" =>
                "socket" => "/var/run/php/php7.0-fpm.sock",
                "broken-scriptfilename" => "enable"


  1. After everything is ready, we can restart lighthttpd.

    $sudo service lighttpd force-reload

  2. After restarting, we can write a PHP file to confirm whether our configuration takes effect.

    $sudo vim /var/www/html/index.php

The contents of the file are as follows:

<? php phpinfo()?>
  1. Finally, we are accessing the Raspberry Pi in the same way as step 4. If you can see a PHP information page, it means that we have successfully built a Lighttpd Web server using PHP on the Raspberry Pi.
  1. Follow Original public account "Liu Xu Linux" and get the latest Linux dry goods as soon as possible!
  2. The public account backstage reply [information][interview][resume]to obtain the interview, self-improvement, resume and other materials of selected top-tier manufacturers.
  3. Follow my blog: