With the Apache and php pre-installed on OS X Mountain Lion, here are the steps I thought sufficient to run a server locally—without installing MAMP (which would install duplicates):
LoadModule php5_module libexec/apache2/libphp5.so
in /etc/apache2/httpd.conf
./etc/apache2/users/calaf.conf
.sudo apachectl start
(or sudo apachectl restart
).<html><head><title>Example</title></head><body><php? echo "Hi"; ?></body></html>
(or rather, be precise, this one) twice—first in /Library/WebServer/Documents/introductory-example.html and a duplicate in ~(whoami)/Sites/introductory-example.html
).I now expect that pointing to either http://localhost/introductory-example.html
or to http://localhost/~calaf/introductory-example.html
will give me a page with two features:
Whether I am looking at the introductory-example.html
in /Library/WebServer/Documents
or in ~/Sites/
I get the first (the title is correct) but not the second (the body is empty)—why?
To my knowledge PHP is not activated system wide. It isn't in any system and/or combination I ever tried anyways. Apache is running PHP for files in a particular folder only (and its sub-folders). The standard apache folder should be in:
/Library/WebServer/Documents/
This guide should get you up and running although I haven't tried it myself.
EDIT:
You need to save a file which contain PHP code in .php, not .html. Rename or re-save the file to introductory-example.php
The following URL do not work since the path does not exist.
http://localhost/Users/calaf/Sites/introductory-example.html
Use the following URL (you maybe need to remove the tilde ~)
http://localhost/~calaf/introductory-example.php