Some characters used here are only viewable on OS X.
It is recommended that you back up the original configuration file before modifying it.
Form A: Graphically
- In the Finder, press ⌘⇧G (Command-Shift-G), and type /etc/apache2 . Press Return or select Go.
- Change the permissions of the httpd.conf file. Select it, press ⌘I (Command-I), open the Sharing and Permissions pane, click the lock, and type in your password (if you have one). Change the privilege of "everyone" to "Read & Write."
- Open the file with a text editor like TextMate or Smultron (the latter is free).
- Find the line that reads #LoadModule php5_module libexec/apache2/libphp5.so and uncomment it (remove the preceding #).
- After the following line, add the lines AddType application/x-httpd-php .php .phtml .php3 and AddType application/x-httpd-php-source .phps to make PHP files recognizable.
- After saving and closing the file, go back to the Sharing & Permissions pane in the Info panel and change the privilege of "everyone" to "Read Only." Click the lock and close the Info panel. You're done!
Form B: In the Terminal
- Open Terminal.app (/Applications/Utilities)
- cd /etc/apache2
- sudo pico httpd.conf (or another text editor of choice)
- press ^W and enter php5
- See step 4 of Form A.
- ^X to quit, Y to confirm, and press Return. You're done!
Remember: PHP is a server-side language, not a client-side one, so you should, after enabling web sharing, at the very least open up your file by opening 127.0.0.1/~UserName/file.php in your browser instead of just dragging in the PHP file. Don't forget to have web sharing turned on (System Preferences > Sharing).