cat brain.log | less

Getting it down on `paper`

Files Ending in .php.html Unexpectedly Being Processed by the PHP Engine

Apache/2.2.3 (Red Hat), PHP 5.1.6 and phpDocumentor v1.4.3 weren’t getting along. phpDocumentor was generating HTML with filenames of the form script.php.html. Apache’s mod_php wanted to interpret script.php.html as a PHP script and was throwing errors about improper formatting:

PHP Parse error: syntax error, unexpected T_STRING in /var/www/default/docs/out/lib/lib/_php---obj---FFT.php.html on line 1, referer:...

I wanted script.php.html to be treated as an HTML file and not be processed by the php engine.  This double-extension was causing me grief.  The docs claimed that only files ending in the extension will be handled by the AddHandler command.  I was incredulous of this claim, especially in light of Apache’s ability to do content negotiation with those .var language files.

Q: Why was this happening? I first guessed it may have been due to mod_mime, but quickly ruled that out.  I then guessed it was the MultiView option… Maybe, this is one mechanism that governs content negotiation… The documentation claims:

# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents.  The MultiViews Option can be used for the
# same purpose, but it is much slower.

This statement lead me to suspect that my problem may actually be caused by an issue with the AddHandler option, since an AddHandler command must be executed to associate type-map with that .var extension.

Ah me, time is money, and in the end, I actually didn’t diagnose the problem, but I did discover (by trial and error) a workaround.

In file /etc/httpd/conf.d/php.conf, I surrounded

AddHandler php5-script .php
AddType text/html .php


<Files ~ "\.php$">
  AddHandler php5-script .php
  AddType text/html .php

Now, only files explicitly ending in “.php” will be treated as a php5-script.  Take that!



No comments so far.

(comments are closed)