Enabling PHP in OS X

Enabling PHP in OS X is really easy. So easy, you might not even know how to do it. Why would you do? Well, if your web host supports it, it might be a good idea to learn a little of it to do some cool things like make easier page titles for individual archives (if you use a lot of template modules, that's a pain) or use some of those cool PHP-only plugins from MT-Plugins. Here's how you do it:

  1. Open up Terminal.
  2. Type in su -
  3. It will ask you for the root password (which you should have enabled already - if not, scroll up to the top and read). Enter the root password and hit enter.
  4. Now, type in cp /etc/httpd/httpd.conf /etc/httpd.conf.php and hit Enter. That just created a backup copy of your Apache config file in case you screw this up.
  5. Next, type in chmod 775 /etc/httpd/httpd.conf
  6. Now comes the fun fun fun stuff. Type in vi /etc/httpd/httpd.conf and hit Enter.
  7. That should bring up a big scary lookin' file. Without worrying about where the cursor is (because there isn't one at the moment), type /php and hit Enter
  8. That should put the big white cursor on a line that says #LoadModule php4_module libexec/httpd/libphp4.so. Move the white cursor with the arrow keys on your keyboard over the # at the beginning of that line. Hit the X key once. That should remove the #.
  9. Ready to do that again? Now, type /AddModule mod_php and hit Enter. That should take you to a line that looks like #AddModule mod_php4.c.
  10. Once again, move the white cursor with the left arrow key until it covers the # at the beginning of that line. When it's covering it up, hit the X key, which should remove the #.
  11. Now, if in any of the above three or four steps, you removed more characters than you should have, fear not! Hit the ESC key and type q! then Enter. You should be back to a Terminal prompt. Start with the vi instruction and continue, repeat as neccessary until you get it right.
  12. All set? Ok, hit the ESC key, then type wq and hit Enter.
  13. Now, fire up System Preferences, go to Sharing, highlight Personal Web Sharing, click Stop, wait 10 seconds, then click Start.
  14. There - PHP is now enabled!

Now what? Go to the PHP Homepage and start reading, Gomer! Now, I know how to turn it on, but I'm no PHP Guru, so take your PHP-specific questions elsewhere, kids.

See also: No Hassle Guide to Installing PHP and MySQL on OS X