UPDATE: Please note that this was written for OS X pre- (High) Sierra. If you are using OSX 10.12 or later, please follow this excellent Andy Miller guide: macOS 10.13 High Sierra Apache Setup: several versions of PHP
I also like to use things that basically already exist. I donβt understand why someone would use MAMP or AMPPS (or any other packaged third-party web server application) when Mac OS X comes with apache and PHP by default.
It took me a few tries to get it to work, so here is basically what did it for me, and hopefully this helps you guys save some time.
As Matt Gibson said, start the terminal and type: (sudo requires your root password)
sudo nano /etc/apache2/httpd.conf
Then uncomment this line by removing the β#β character in front of it (Ctrl + V can be used as a page down).
LoadModule php5_module libexec/apache2/libphp5.so
To make sure you can include files, etc. In PHP, highlight "User _www" (in my case) and change it to: (where "yourusername" is the user you are logging in with)
User yourusername
You can leave the group as is, Group _www by default with a new installation of OS X Mountain Lion.
By default, apache only searches index.html, so look for "DirectoryIndex index.html" and change it to: (adding index.html at the end is optional, of course)
DirectoryIndex index.php index.html index.htm
Exit and save by pressing Ctrl + X (and confirm by pressing "y")
Then restart Apache:
sudo apachectl restart
My phpinfo (); returns with PHP version 5.3.15
===================
Since I find it useful to have my local sites in my user directory, I created the directory / Users / yourusername / Sites (which is no longer the default in Mountain Lion).
Edit httpd.conf again through "sudo nano / etc / apache2 / httpd.conf" and ...
Scroll down to "DocumentRoot" and change it to: (where "yourusername" is the name of the user you are logging in with)
DocumentRoot "/Users/yourusername/Sites/"
Scroll to where it says: "# This should be changed to what you set for DocumentRoot." and change the following line to: (where "username" is the name of the user you are logging in with)
<Directory "/Users/yourusername/Sites/">
Then exit and save by pressing Ctrl + X (and confirm by pressing "y")
Restart Apache.