lighttpd serves HTML fine but answers 403 Forbidden for every .php file
Fix it fast
Most common cause, 1 of 3No FastCGI handler is configured for .php
Install PHP-FPM, enable Debian's fastcgi and fastcgi-php-fpm snippets, and restart lighttpd.
sudo apt install php-fpm
sudo lighty-enable-mod fastcgi fastcgi-php-fpm
sudo grep -R "^listen = " /etc/php/*/fpm/pool.d/
sudo systemctl restart lighttpdShort answer
lighttpd answers 403 Forbidden for .php when nothing runs the file: the shipped config puts .php in static-file.exclude-extensions, so without a FastCGI handler no module takes the request. On Debian and Ubuntu, enable fastcgi and fastcgi-php-fpm with lighty-enable-mod. If the body reads Access denied., PHP-FPM refused instead: its pool user cannot read the script, or the extension is not allowed.
Which cause do you have?
Request the page and read the body: lighttpd's own 403 page means no handler took the request, while a one-line Access denied. comes from PHP-FPM. Then read the lighttpd error log.
curl -si http://localhost/index.php | head -n 15
sudo tail -n 20 /var/log/lighttpd/error.logThen find the line you see in this list and open its fix:
- 1No FastCGI handler is configured for .php
HTML and images load, each .php URL gets lighttpd's 403 page, and nothing mentions Access denied. - 2The PHP-FPM pool user cannot open the script
The body is Access denied. and the PHP-FPM log shows Unable to open primary script ... (Permission denied) - 3security.limit_extensions refuses the file's extension
Access denied. only for files such as .phtml, .php5 or .html sent to PHP, while plain .php files work
What does the error look like?
403 Forbidden-- NOT handling file as static file, extension forbiddenAccess denied.Unable to open primary script: /var/www/html/index.php (Permission denied)Access to the script '/var/www/html/page.phtml' has been denied (see security.limit_extensions)
Cause 1 of 3
No FastCGI handler is configured for .php
You seeHTML and images load, each .php URL gets lighttpd's 403 page, and nothing mentions Access denied.
Check
lighttpd sends 403 Forbidden for PHP files when no module accepts the request. lighttpd's annotated sample configuration and the lighttpd.conf shipped by Debian and Ubuntu both list .php in static-file.exclude-extensions, which forbids handing out the source, so mod_staticfile steps aside; with no fastcgi.server entry for .php either, lighttpd closes the request with 403. Setting debug.log-request-handling = "enable" makes the error log say NOT handling file as static file, extension forbidden.
ls /etc/lighttpd/conf-enabled/
sudo lighttpd -p -f /etc/lighttpd/lighttpd.conf | grep -n -A4 "fastcgi.server"Fix
Install PHP-FPM, enable Debian's fastcgi and fastcgi-php-fpm snippets, and restart lighttpd. If your pool listens on another socket than the one in 15-fastcgi-php-fpm.conf, edit that path to match.
sudo apt install php-fpm
sudo lighty-enable-mod fastcgi fastcgi-php-fpm
sudo grep -R "^listen = " /etc/php/*/fpm/pool.d/
sudo systemctl restart lighttpdVerify
A small test script now returns 200 instead of 403.
curl -sI http://localhost/index.php | head -n 1Confirmed by redmine.lighttpd.net
Cause 2 of 3
The PHP-FPM pool user cannot open the script
You seeThe body is Access denied. and the PHP-FPM log shows Unable to open primary script ... (Permission denied)
Check
Here lighttpd did pass the request on, and PHP-FPM itself replied 403. FPM opens the script as the user and group named in its pool file, and when that account lacks read access to the file, or search access to a folder above it, FPM logs the open failure and returns the short Access denied. body.
sudo grep -E "^(user|group) = " /etc/php/*/fpm/pool.d/www.conf
namei -l /var/www/html/index.phpFix
Give the pool's group read access to the code and search access to its folders, or change the pool user to the owner of the site files.
# use the group printed from the pool file
sudo chgrp -R www-data /var/www/html
sudo chmod -R g+rX /var/www/htmlVerify
The page renders, and the FPM log stops reporting the open failure.
curl -s http://localhost/index.php | head -n 5Confirmed by github.com
Cause 3 of 3
security.limit_extensions refuses the file's extension
You seeAccess denied. only for files such as .phtml, .php5 or .html sent to PHP, while plain .php files work
Check
PHP-FPM parses a main script only when its name ends in one of the extensions in security.limit_extensions, which defaults to .php .phar. A fastcgi.server key for another extension sends those files to FPM anyway, and FPM turns them away with 403 and a notice naming security.limit_extensions.
sudo grep -R "limit_extensions" /etc/php/*/fpm/Fix
Rename the files to .php if you can. Otherwise add the extension in the pool file and restart the FPM service for your PHP version.
# /etc/php/8.3/fpm/pool.d/www.conf
security.limit_extensions = .php .phtml
sudo systemctl restart php8.3-fpmVerify
The .phtml page renders, and no new limit_extensions notice appears in the FPM log.
curl -sI http://localhost/page.phtml | head -n 1Confirmed by php.net
How do I stop it coming back?
- Keep a one-line PHP health page and request it after every lighttpd or PHP upgrade, since a package change can leave the fastcgi snippets disabled.
- Leave static-file.exclude-extensions in place so a broken PHP handler gives a 403 instead of serving your source code.
- Deploy code with a group the FPM pool belongs to and modes such as 640 for files and 750 for folders, set by the deploy script.
Sources
- lighttpd: mod_fastcgi
- lighttpd: mod_staticfile (exclude-extensions)
- lighttpd: configuration options (debug.log-request-handling)
- lighttpd source: response.c (403 when no handler)
- lighttpd annotated sample configuration
- PHP manual: FPM configuration (security.limit_extensions)
- php-src: fpm_main.c (Access denied responses)
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Spotless Laundry, EZ Estimater.