PHP file won’t open in browser, only download

apache-http-serverPHP

I can't get .php files to run on my server. For example, I created a test file entitled "test.php" with the following content (only):

<?php
phpinfo() ;
?> 

When I try to open this or other php files through a web browser, it tries to download them rather than run them. Responses to similar questions suggest that this issue means the server isn't set up to run php. I looked up how to enable php on the server and found that I am supposed to uncomment the line

LoadModule php5_module libexec/apache2/libphp5.so

in the httpd.conf in the etc/apache2 directory. However, when I checked that file, the above line was already uncommented. Is there some other thing I need to change to make php work correctly?

Best Answer

You also need to add the handler for the PHP extension, so that the scripts are actually handled by the PHP module.

AddHandler php5-script .php
Related Question