docker-library / docker-library/php

Incompatibility with FallbackResource and SetHandler

Open
#1,576 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dockerfile
Stars
4k
Forks
2k
Avg merge
5d 21h
Merged PRs (30d)
1

Description

I've just encountered an issue whereby our FallbackResource is applied correctly, except where the URL requested ends in .php.

For example:

  • http://localhost/example.html => Uses FallbackResource
  • http://localhost/example.php => Does not use FallbackResource and results in a 404

It seems that it's because the docker-php.conf configuration file sets the PHP Handler for any file which matches .php, and therefore the FallbackResource (handler) is not applied.

<FilesMatch \.php$>
	SetHandler application/x-httpd-php
</FilesMatch>

https://github.com/docker-library/php/blob/master/8.4/bookworm/apache/Dockerfile#L97-L99

This has been raised (and rejected) in the Apache Bugzilla:
https://bz.apache.org/bugzilla/show_bug.cgi?id=52403#c7

There seems to be a few possible solutions:

  1. Use AddType instead of AddHandler or SetHandler. I'm not sure if this is suggestion on the bz issue is from the Apache team, or is an observeration. I'm not sure whether this is a viable option
  2. Wrap the SetHandler call in a conditional
  3. Switch to mod_rewrite (not generally recommended now that FallbackResource exists)

Re 2, the change would be something like this:

<FilesMatch \.php$>
    <If "-f %{REQUEST_FILENAME}">
        SetHandler application/x-httpd-php
    </If>
</FilesMatch>

(Suggestion found here: https://stackoverflow.com/questions/50439963/apache-fallbackresource-configuration)
This would likely have a performance impact, but I would imagine no worse than using mod_rewrite.

I've tested the conditional SetHandler locally and it works as expected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with 8.4/bookworm/apache/Dockerfile around lines 97-99 and the generated docker-php.conf containing the FilesMatch SetHandler rule. Reproduce the reported FallbackResource behavior for existing and missing .php URLs, then evaluate the proposed handler configurations. Done means PHP files still use the PHP handler while missing .php URLs reach FallbackResource without a 404.

Written by the indexing model from the issue text.

Assessment

Tech stack
apache, docker, php
Domain
devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.