As i understand when the server (e.g. Apache) receives a request it looks for file name extension to find associated mime-type. Then it looks for the handler handling this mine-type (i'm stating it based off adding PHP support to Apache). And here are my questions:

  1. Is the above statement correct?
  2. If so when there is no handler for given mime-type does it mean the default behavior - that is just send a file to the client?
  3. If there is even no explicit extension - mime-type association defined (e.g. .html) the default action again is just send a file to the client?
  4. According to some sources to add PHP support to Apache we have to use addType directive:AddType application/x-httpd-php .php while others say to use addHandler directive:AddHandler application/x-httpd-php .php which in my opinion is the only correct becouse addType should be used only for static documents. So why the addType version is still correct?
  5. I found somewhere such a lines:

AddType text/html .php .phps
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps

Does it mean that AddType directive will be used if the server can't find the handler for application/x-httpd-php mime-type and the action would be just to send .php source file to the client with text/html mime-type in response?

  • I've rolled back your edit, please don't do that. If you're getting the wrong answers, then improve your question and its title. – Arjan Aug 26 '16 at 21:23
  • Please note that this site is mainly for concrete problems that need solutions. Stuff like „I tried to install PHP on my Apache, but it’s not working!”. All I see in this question is rather “philosophical”. It’s also totally specific to Apache. – Daniel B Aug 26 '16 at 21:27
  1. Yes and no. There is always a type and a handler. If you look at the documentation for handlers it states:

    Generally, files have implicit handlers, based on the file type. Normally, all files are simply served by the server, but certain file types are "handled" separately.

As such it's likely that you can configure handlers separately from the type. As in my original answer it looks like it's what the PHP INSTALL file suggests by now.

  1. If you look at the link above it would be the default handler that is called which probably just sends the file as it is the most common use for a web server.

  2. I don't understand what you mean by that. If a file has an extension but that extension has no mime type associated the default mime type is used. If you look at the post How can I make all unrecognized file types as binary in Apache2? the default mime type should be text/plain as per documentation about the core module.

  3. / Original answer: If you're looking for a source on how to add PHP support to Apache why not just consult the INSTALL file included with the PHP download?

According to it for Apache 2.x with PHP 5.6.25 you'd use SetHandler.

Now if you look at your example:

AddType text/html .php .phps
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps

You're correct that according to the Apache documentation of AddType it should be used for static files. Using AddHandler on the other hand might pose a security risk. At least it's not recommended by the INSTALL file from PHP and it specifically mentions that a pure AddType might lead to file being executed that are not actually really PHP files. From the INSTALL file point 8 for Apache 2.x:

Tell Apache to parse certain extensions as PHP. For example, let's have Apache parse .php files as PHP. Instead of only using the Apache AddType directive, we want to avoid potentially dangerous uploads and created files such as exploit.php.jpg from being executed as PHP. Using this example, you could have any extension(s) parse as PHP by simply adding them. We'll add .php to demonstrate.
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>

If you look at the documentation about AddHandler / SetHandler it becomes clear that AddHandler and SetHandler would serve slightly different purposes and that the suggestion from the INSTALL file would "encourage" you to send your own headers as the internal, core handler for php files would change.

  1. No, it means the default mime type that is send to the client would be text/html as it is pretty likely that php files generate html output.
|improve this answer|||||
  • Sorry, but Yours answer if useless form me. It doesn't answer any of my questions. Moreover it brings even more questions and confusion to me;-( Can You be so nice and try to clearly answer all my questions? – Mulligan Aug 26 '16 at 12:52
  • Can You be so nice and respond to my last comment? – Mulligan Aug 26 '16 at 14:10
  • So @Mulligan could you tell me if this one is better or tell me what your issues are with it? – Seth Aug 30 '16 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.