Apache configurations for php "AddType text/html php" or "AddType application/x-httpd-php php .php"

6,747

The mod_mime AddType definition from the Apache httpd docs:

The AddType directive maps the given filename extensions onto the specified content type. MIME-type is the MIME type to use for filenames containing extension. This mapping is added to any already in force, overriding any mappings that already exist for the same extension. This directive can be used to add mappings not listed in the MIME types file

In short AddType text/html php tells httpd to specify the Content-Type header for PHP files to be text/html. Which is correct since it is used by the client side browser and not the server itself.

What tells httpd to handle the files as PHP is the SetHandler directive:

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

The PHP configuration instructions explain the SetHandler directive in relation to PHP as well.

Share:
6,747
forestclown
Author by

forestclown

Updated on September 18, 2022

Comments

  • forestclown
    forestclown over 1 year

    I am taking over an application server and discover that it contain the following settings:

    AddType text/html       php
    

    Although it works, but my understanding is that it should set as following:

    AddType application/x-httpd-php php .php
    

    What are the key differences between the two settings? Although at this point my application (Built using CakePHP) is running fine with either configuration, but I am not sure if it will cause any strange behaviour.

    Thanks!