Hot Fix: Apache Displays Contents of PHP Script Instead of Running Script

If you have ever installed Apache HTTP Server and had it up and running perfectly without any issues, you are truly a genius or very lucky. Inevitably, you are going to encounter a few hiccups if you are doing things manually. With all of the imaging, virtual machines, and hosting automation technology, few system administrators still do it the old fashioned way.

You may happen to encounter a situation where you have installed Apache, installed PHP, and appear to have everything up and running but then realize that websites are displaying the contents of PHP files rather than running them as scripts. If you have verified that the PHP module is installed and running, you may be able to use this simple hot fix.

In your apache2.conf or httpd.conf file (often located in /etc/httpd or /etc/apache2), add these lines:

AddType application/x-httpd-php .php

This will tell Apache to recognize PHP files as an application type. Normally, this should happen with your normal installation automatically, but if it does not, this fix should be all you need.











Comments: