Enable PHP on Mac OS X

Posted by Matt Thommes on November 27, 2008 | Post type: Gain

Mac OS X "Leopard" (10.5) ships with PHP already installed - all you have to do is enable it. I found this a bit tricky at first, since this is not a global system preference.

Go to the Finder, and choose Go > Go to Folder, or hit Command + Shift + G.

Screenshot of Mac OS X Finder

Type /private/etc/apache2/ in the box:

Screenshot of Mac OS X dialog

You'll then be taken to a private folder location, where you'll see a file called httpd.conf.

Screenshot of Mac OS X Finder

Open that file in any text editor.

Scroll down to line 114, which will initially look like this:

Screenshot of text editor

Notice the preceding "#" character at the beginning of the line. This indicates that the line is commented out, meaning it is ignored. We'll want to change it so this line is not ignored. Simple remove the "#" character, and save your changes.

Screenshot of text editor

You've just enabled PHP.

Turn on Web Sharing

In order for PHP to be used, you'll need to take one more step and make sure Web Sharing is turned on. In System Preferences, click on Sharing under the Internet & Network section.

Screenshot of Mac OS X System Preferences

Screenshot of Mac OS X System Preferences

Once Web Sharing is turned on, you'll have a unique URL and directory to maintain your PHP site files.

Your URL is what's listed in the Sharing preferences pane. Above we see http://192.168.2.105/~matthom/, which is the URL to my user account's home directory. Every user on Mac OS X gets their own home directory. You could also use http://localhost/~matthom/ instead, which points to the same location.

Your web directory is under the Sites folder.

Screenshot of Mac OS X Finder

Put your PHP files in here, and develop your own PHP applications on Mac OS X!

About the author(s)

Matt Thommes is an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Comments

Note: Comments may be viewed by authors, but if you have a more specific question you'd like to ask them, please email matt.thommes@paininthetech.com.

# boarder34 at 2/1/2009 8:24 am cst

hey man when i try to change the php thing in text edit it says i dont have permission to change the file what do i do then?

Quick Link to this comment: http://TTIP.me/c4901

# tom at 2/18/2009 5:50 pm cst

I went down the same rat hole not understanding that I needed to change the permissions for the "Folder" not the file that I was working with. But that does not take away from the fact that your information was very helpful.

Thanks

Quick Link to this comment: http://TTIP.me/c4928

# Tom Holder at 3/3/2009 2:41 pm cst

AWESOME

Perfect guide after finding endless nonsense regarding this issue!!

Make sure you change the Apache2 folder permissions then you can make the changes to httpd.conf

Quick Link to this comment: http://TTIP.me/c4957

# Lori at 11/9/2009 7:56 pm cst

Excellent guide. Thank you very much!!!

Quick Link to this comment: http://TTIP.me/c5412