How to Set Up Lighttpd with PHP‑FPM on a Raspberry Pi
This step‑by‑step guide shows how to install and configure Lighttpd on a Raspberry Pi, replace Apache, enable PHP‑FPM, adjust FastCGI settings, and verify the web server works with both static HTML and PHP pages.
Lighttpd, like Nginx, is designed for low‑memory, low‑CPU devices and runs well on a Raspberry Pi. This tutorial explains how to install a basic Lighttpd configuration on the Pi and integrate it with PHP‑FPM.
Prerequisites
Raspberry Pi with a recent Debian‑based OS.
Internet connection for package installation.
Installation Steps
Update the system packages:
$ sudo apt-get update
$ sudo apt-get upgradeRemove any existing Apache2 installation (skip if already removed): $ sudo apt-get remove apache2 Install Lighttpd: $ sudo apt-get install lighttpd Verify Lighttpd is running by opening the Pi’s LAN IP address in a browser. Find the IP with: $ hostname -I The default page will be displayed.
Optionally edit the default HTML page: $ sudo vim /var/www/html/index.html Install PHP‑FPM (PHP 7 is recommended for better performance and memory handling): $ sudo apt-get install php7.0-fpm Enable FastCGI modules for Lighttpd:
$ sudo lighttpd-enable-mod fastcgi
$ sudo lighttpd-enable-mod fastcgi-phpConfigure Lighttpd to use PHP‑FPM instead of the default PHP‑CGI. Edit the FastCGI config file:
$ sudo vim /etc/lighttpd/conf-available/15-fastcgi-php.confReplace its contents with the following snippet:
# -*- depends: fastcgi -*-
# /usr/share/doc/lighttpd/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi
## Start a FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
((
"socket" => "/var/run/php/php7.0-fpm.sock",
"broken-scriptfilename" => "enable"
))
) )Reload Lighttpd to apply the changes: $ sudo service lighttpd force-reload Create a simple PHP file to test the configuration: $ sudo vim /var/www/html/index.php Insert the following content: <?php phpinfo(); ?> Access the Pi’s IP address again in a browser. If a PHP information page appears, Lighttpd with PHP‑FPM is successfully set up.
Images in the original article illustrate each step; they have been retained for reference.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
