Parsing .html files for php code

May 30, '03 09:26:00AM

Contributed by: kahless

I recently wanted to add some PHP code to my web pages, giving the last modification date. The PHP code to do this is:

<?php
putenv("TZ=America/New_York");
echo "Last modified: " .date("F d Y ", getlastmod());
echo "at "  .date("h:i:s A.",getlastmod());
?>
The problem was that all of the pages were .html files, and Apache isn't set up by default to parse .html for PHP code. A search on the web for help found a page [nonpplus.net] that suggested that one add the following to an .htaccess file and place the file in the directory to be affected:
AddType application/x-httpd-php .htm .html.
However, I wanted my whole /Users/user_name/Sites folder to have .html, .htm, and .php parsed for PHP code, so I added
RemoveHandler .htm .html
AddType application/x-httpd-php .php .htm .html
to the bottom of my user_name.conf file in /etc/httpd/users by typing:
sudo pico /etc/httpd/users/username.conf
(Enter your password when prompted). I would assume you could set Apache to parse all .htm, .html, and .php files for PHP by adding some version of the above to httpd.conf in /etc/httpd, but this might have a huge impact on the server's performance. This hint really just collects together two useful pieces of information in one place, but I hope somebody else finds it helpful.

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030526235224940