Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

lighttpd serves HTML fine but answers 403 Forbidden for every .php file

Your error

403 Forbidden4 more lines it can show

Fix it fast

Most common cause, 1 of 3

No FastCGI handler is configured for .php

Install PHP-FPM, enable Debian's fastcgi and fastcgi-php-fpm snippets, and restart lighttpd.

Fix
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 lighttpd
Did this fix it?
Full steps for this cause: check, fix, verify

Short 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.

  • Applies to lighttpd 1.4.74 (Ubuntu 24.04) to 1.4.85, PHP-FPM 8.3 to 8.6, Debian 13, Ubuntu 24.04 and 26.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
curl -si http://localhost/index.php | head -n 15
sudo tail -n 20 /var/log/lighttpd/error.log

Then find the line you see in this list and open its fix:

  1. 1No FastCGI handler is configured for .phpHTML and images load, each .php URL gets lighttpd's 403 page, and nothing mentions Access denied.
  2. 2The PHP-FPM pool user cannot open the scriptThe body is Access denied. and the PHP-FPM log shows Unable to open primary script ... (Permission denied)
  3. 3security.limit_extensions refuses the file's extensionAccess 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 forbidden
  • Access 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.

Check
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.

Fix
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 lighttpd

Verify

A small test script now returns 200 instead of 403.

Verify
curl -sI http://localhost/index.php | head -n 1

Confirmed by redmine.lighttpd.net

Did this fix it?

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.

Check
sudo grep -E "^(user|group) = " /etc/php/*/fpm/pool.d/www.conf
namei -l /var/www/html/index.php

Fix

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.

Fix
# use the group printed from the pool file
sudo chgrp -R www-data /var/www/html
sudo chmod -R g+rX /var/www/html

Verify

The page renders, and the FPM log stops reporting the open failure.

Verify
curl -s http://localhost/index.php | head -n 5

Confirmed by github.com

Did this fix it?

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.

Check
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.

Fix
# /etc/php/8.3/fpm/pool.d/www.conf
security.limit_extensions = .php .phtml

sudo systemctl restart php8.3-fpm

Verify

The .phtml page renders, and no new limit_extensions notice appears in the FPM log.

Verify
curl -sI http://localhost/page.phtml | head -n 1

Confirmed by php.net

Did this fix it?

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

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.