Lighttpd is a high-performance, low-memory-footprint web server designed for speed and efficiency. When paired with PHP, a widely used server-side scripting language, you can build scalable and fast web applications—ideal for embedded devices, small websites, or performance-focused deployments.
Before configuration, ensure both Lighttpd and PHP are installed on your Linux server. Follow these installation commands:
sudo apt-get update
sudo apt-get install lighttpd
sudo apt-get install php php-cgi php-mysql
By default, Lighttpd doesn't parse PHP files. Manual configuration is required to enable PHP support.
Edit the Lighttpd config file:
sudo nano /etc/lighttpd/lighttpd.conf
Locate and modify the server.modules section to include:
server.modules = (
"mod_access",
"mod_alias",
"mod_cgi"
)
In the same config file, add the following PHP handler configuration:
server.modules += ( "mod_fastcgi" )
mimetype.assign = (
".php" => "application/x-httpd-php"
)
fastcgi.server = (
".php" => ((
"socket" => "/var/run/php/php7.4-fpm.sock",
"bin-path" => "/usr/bin/php-cgi",
"check-local" => "disable",
"max-procs" => 1,
"bin-environment" => (
"PHPRC" => "/etc/php/7.4/cli/php.ini"
)
))
)
To apply changes, restart Lighttpd:
sudo service lighttpd restart
Create a PHP test file named info.php:
<?php phpinfo(); ?>
Place this file in your web root (typically /var/www/html) and visit http://your_server_ip/info.php in a browser. If configured correctly, you will see the PHP information page.
If the browser displays PHP source code instead of executing it, this usually means PHP isn't being parsed correctly. Double-check that mod_fastcgi is enabled and PHP is correctly configured.
This may indicate a PHP configuration error or permission issue. Check Lighttpd's error log at /var/log/lighttpd/error.log for detailed information.
With this setup, you can successfully run PHP on a Lighttpd server. This combination is fast, lightweight, and ideal for small to medium-scale projects. Proper configuration ensures high performance and a responsive web environment tailored to your deployment needs.