Enable PHP on Mac OS X

November 27, 2008 / Filed under:

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 the file to enable PHP was a tad difficult to physically find.

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. Simply 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!

Comments/Mentions

# 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?

# 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

# 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

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

Excellent guide. Thank you very much!!!