MacOS – Unable to enable PHP in OSX 10.8 mountain lion

apachemacosPHP

I have enabled php according to PHP's instructions and uncommented,

#LoadModule php5_module libexec/httpd/libphp5.so

in /private/etc/apache2/httpd.conf. However the line,

#AddModule mod_php5.c

does not exist in that file, nor do any #AddModule lines. This may be the root of my problem but regardless I restarted apache with,

sudo apachectl restart

and attempted to open ~/Site/page.php

<html>
<head>
<title>My First PHP page </title>
</head>
<body>
<?php echo "<h1> Hello World! </h1>";?>
</body>
</html>

in multiple web browsers. Safari and Chromium just gave me the raw text of the file and Opera gave me

Hello World ";?>

Do I need to configure apache to add that module and how do I do that, or is there some other problem?

PS, I couldn't even open page.php with safari when it was in my home directory and other browsers tried to download it.

Best Answer

If the line doesn't exist commented-out, then just add it separately. i.e. put a line in httpd.conf that reads AddModule mod_php5.c.