Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 279099 - PHP 5 default apache configuration uses "FilesMatch" containers to specify when it would be better to use simple "AddHandler" directives
Summary: PHP 5 default apache configuration uses "FilesMatch" containers to specify wh...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: AMD64 Linux
: High minor (vote)
Assignee: PHP Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 274512
  Show dependency tree
 
Reported: 2009-07-25 20:40 UTC by Timothy Benjamin Martin
Modified: 2010-09-23 04:19 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Benjamin Martin 2009-07-25 20:40:29 UTC
The default apache configuration file installed with php 5 sets the server handler by nesting the "SetHandler" directive inside "FilesMatch" containers. Because of the way that those containers work it's somewhat difficult to manually override the handler or even troubleshoot why a file is being handled in a particular way.

I propose that using a simple AddHandler instead is easier to deal with and even easier to read and understand when looking at config files.

A good use case is if you have a virtual host on another port that you want to serve out with webdav for editing. You'll want those files to not be processed and instead served as plain/text. You would normally use a ForceType or RemoveHandler directive, but neither of these works with the default config because FilesMatch is evaluated very late in the order and overrides everything else.

Reproducible: Always

Steps to Reproduce:
1. Install with the default config files
2. Set up a location or directory where you want php files to be served without processing (as text) either for webdav or just simply for viewing purposes. Try to use the common ForceType or RemoveHandler directives to accomplish this.
Actual Results:  
It will still parse and server-side process the php and send the output to the client


Expected Results:  
That you could use these directives to stop the server-side processing of php files.

This is what's in the default config:

    <FilesMatch "\.ph(p5?|tml)$">
        SetHandler application/x-httpd-php
    </FlesMatch>

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

and those six lines can be replaced with these two:
 
    AddHandler application/x-httpd-php .php .php5 .phtml
    AddHandler application/x-httpd-php-source .phps
Comment 1 Christian Hoffmann (RETIRED) gentoo-dev 2009-07-27 10:29:14 UTC
You are right, I did not think of that at all, will change in the next revision.
Comment 2 Brandon Turner 2010-03-04 02:26:34 UTC
One thing to keep in mind if implementing this:

Using mod_mime's AddHandler causes the handler to be used if the filename *contains* the extension rather than *ends with* the extension.  So a file
  mycode.php.html
will be parsed as a PHP file when AddHandler is used, but not when the FilesMatch directive is used.

This may be what people want, or it may not.  But either way, this change is not without consequences, however minor they might be.

For more info, see:
http://httpd.apache.org/docs/2.2/mod/mod_mime.html#multipleext
Comment 3 Matti Bickel (RETIRED) gentoo-dev 2010-06-09 08:56:13 UTC
The current in tree php-5.3.2 uses AddHandler like you suggested. Thanks.
Comment 4 Mr.Patt Emmawat 2010-09-23 04:19:40 UTC
I change
    AddHandler application/x-httpd-php .php .php5 .phtml
    AddHandler application/x-httpd-php-source .phps
to
    AddHandler application/x-httpd-php5 .php .php5 .phtml
    AddHandler application/x-httpd-php5-source .phps