Enable PHP in OS X

This works if you are running OS X 10.2.3 or (hopefully this will work with future updates too) later.
Apple ships apache with OS X. It also ships with php, but is disabled by default. With a single click of the mouse at the sharing control panel you can start serving a web page using apache! But if you want to do a couple of more advanced things, like use php suddenly you are neck deep in .config files and using the command line. Scary. Here are the simple(ish) steps to get php working. This is meant to get php working for you fast, not to explain what you are doing or why.

  1. Figure out how to open text files as root.
  2. navigate to or find /private/etc/httpd/
  3. From that directory make a backup copy of “httpd.conf” put it somewhere safe
  4. Look around! This is an interesting file that controls how your apache works. You can learn a lot just by looking.
  5. find these two lines of text:
    • LoadModule php4_module
    • AddModule mod_php4.c
  6. Remove the “#” sign from in front of each line. This “uncomments” it, making it readable by apache. Save your changes.
  7. Find the following text:

    # AddType allows you to tweak mime.types without actually editing it, or to

    # make certain files to be certain types.

    and replace it with:

    # AddType allows you to tweak mime.types without actually editing it, or to
    # make certain files to be certain types.
    For PHP 4.x, use:
    AddType application/x-httpd-php .php

  8. Restart apache by using the sharing control panel, or typing sudo apachectl restart (thats an “L” at the end of “apachectl” not a numeral “1″
  9. Create a web page called test.php or whatever, and put in this in the body of your page: <?php phpinfo(); ?>.
  10. view this page in a browser. Make sure you are not looking at the local file, but at the page using your internet address, as if you were an outside visitor. This will show you all sorts of cool stuff about your configuration, and confirm that php is working.
  11. Good Luck!

Leave a Reply



Search WWW Search aliandcedar.com