News Archive
PhpRiot Newsletter
Your Email Address:

More information

A MIME type for .php files

Note: This article was originally published at Planet PHP on 13 April 2011.
Planet PHP

While setting some svn properties at work, we wondered about the correct MIME type for .php files.

Looking around in the various magic MIME type detection lists on our unix machines and the official IANA MIME type list . The options we came up with were:

  • text/php
  • text/x-php
  • application/php
  • application/x-php
  • application/x-httpd-php
  • application/x-httpd-php-source

MIME type rules

Since there is no official MIME type registered at IANA, only an extension type (x- prefixed) can be used - which means that text/php and application/php are not suitable:

Any unregistered file type should be listed with a preceding x-, as in application/x-foo (RFC2045 5.1), or a x., as in application/ (RFC4288 4.3). Any non x-prefixed type should be registered with IANA and listed at the above address. Any other behavior is a MIME standards violation!

Linux distributions

Ubuntu's magic MIME database - used by the file command - spits out text/x-php:

$ file -i update-file.php update-file.php: text/x-php; charset=us-ascii

Debian's mime-support package, also shipped by Ubuntu, lists application/x-httpd-php for .php and application/x-httpd-php-source for .phps files in /etc/mime.types. This two types are - in my eyes - more for internal Apache/webserver use since PHP is not only usable within a web server.

IANA considerations

What's left are text/x-php and application/x-php. I personally prefer text/* for user readable plain text files, which is why I was sceptical about application/x-php at first. Then I saw that in 2006, IANA officially assigned application/javascript for JavaScript code files - and not text/javascript. The RFC states:

Use of the "text" top-level type for this kind of content is known to be problematic.

- but fails to state why that is so. I guess this is because security problems arise since browsers display every text/ MIME type as html.

A similar reasoning was used when applying for the JSON MIME type that was officially assigned in RFC 4627:

When asked about why not "text/json", Crockford seems to have said JSON is not really javascript nor text and also IANA was more likely to hand out application/* than text/*.

Other languages

Looking at the officially assigned text/ types makes clear that there is not a single programming language source file type in the club. (html is, as the name implies, a markup and not a programming language - which is why text/html does not count .)

The list of application/ types on the other hand contains types like application/ecmascript and application/javascript, both programming languages. Further, even Debian puts several programming languages into the application group: application/x-ruby, application/x-sh and application/x-tcl.


Putting programming languages under the application group has statistical significance and is also backed by previous IANA decisions. So it seems it's inevitable to use application/x-php as MIME type for .php files.