---- Serving PHP with Apache: AddType and AddHandler
jmnielsen7 - 5:36 pm on Mar 22, 2013 (gmt 0)
***Relevant to the OP!***
After a bit more digging I discovered how "application/x-httpd-php" (a MIME type - as jdMorgan pointed out) can be used as a Handler, and honestly it seems a bit like slight-of-hand. I would have to say in a somewhat *unfortunate* overlap of naming, the Apache Action directive allows a CGI script to be mapped directly to a MIME media type name as a handler. Then once defined/mapped with an Action directive that Action-name (it no longer refers to the MIME type in the syntactical context of the AddHandler directive but rather to a mapped Action-name) can be called by AddHandler as a user-defined handler name. Also Action can define any arbitrary string name which can equally be used by AddHandler.
My first pointer was from a Google Books preview of the book "Pro Apache" on page 350 here [books.google.com] where it says:
The Action directive allows CGI scripts to be used as handlers. It has two variants: associating a script with either a media type or an arbitrary name, which can then be used by the AddHandler and SetHandler directives.
Apache understands several different MIME types for differentiating various kinds of media. You can add your own handler to process one of them by using the Action directive with a MIME-type parameter:
Action image/gif /cgi-bin/gifconvert.cgi
You can invent new media types or supplement existing ones using AddType in combination with Action, but this approach is deprecated in favor of using AddHandler or SetHandler. For example, to allow a different extension for SSIs, you could use this:
AddType application/x-server-parsed .ssi
or to invent a completely new media type and have it parsed with your own handler, you could use this:
In addition to the internal handlers provided by Apache modules, you can also define your own handlers with the Action directive. This is similar to using Action with MIME types but with an arbitrary handler name:
This provides an excellent way to hide CGI scripts behind seemingly ordinary URLs; the handler can be associated with a directory, and then any file request in that directory will instead go to the handler."
Okay, so how is this relevant to the question in the OP about what AddHandler application/x-httpd-php .php does? As jdMorgan pointed out (in the quotes I made in an earlier post) it APPEARS that "the use 'AddHandler application/x-httpd-php .php' to declare a MIME-type as a content-handler is glaringly nonsensical", but the fact is that it actually is the result of AddHandler being paired with a corresponding Action directive (which must be present or it will never work!), which ties the MIME type media name to a CGI script and provides that name as a new handler name. And it is a little unclear but it seems that if a MIME type is not by default defined or known to Apache you can use AddType to define one ("invent a completely new media type") and then use it with Action. So AddHandler and Action may or may not also need to be paired with AddType (try without it first though to avoid unnecessary issues).
And once I discovered the above information, lo and behold, what do I find on the Apache wiki for PHP4/PHP5 [wiki.apache.org]? I find instructions to add the following to httpd.conf:
So the "Action application/x-httpd-php modules/libphp5.so" directive here was the missing piece to the puzzle all along! This is probably why so many Joomla and Wordpress configurations were messed up when people were complaining about "AddHandler application/x-httpd-php .php", because they had no corresponding Action directive that mapped the MIME media type name to a CGI script (they were calling an undefined handler name). So Voilą! Mystery solved.