Topic: Tutorial: Configuring Apache/php on Mac OS X Snow Leopard

July 26th, 2010

This is a tutorial on how to configure apache2 and php for Mac OS X Snow Leopard. I'm not covering installation because these two come installed with Snow Leopard. Getting apache up can be nice if you intend to use Phusion Passenger. This tutorial is mostly oriented towards beginners.


Mac OS X Snow Leopard 10.6
Apache: 2.2.14 (comes with Snow Leopard)
PHP: 5.3.1 (come with Snow Leopard)
Text editor (I use text mate)
Using terminal, found in Applications/Utilities/Terminal

Since pretty much all the command line commands and configuring requires root permissions or using the ‘sudo’ (superuser do) command, It will be easier to just open the terminal and type ‘sudo –s’ which will start a terminal session acting as root user. You will have to enter your password to do so.

From here on, I’m assuming that you will type ‘sudo –s’ to start a session as root user, otherwise most of these commands will have to be prefixed with ‘sudo’.

Here’s how to find what versions you have if any (go to terminal and type these commands)
Apache: ‘httpd –V’
PHP: ‘php –verison’

We are going to type commands, like:

your_texteditor_name file_name

to open files in the command prompt(terminal).This assumes you have installed the Unix command for your text editor. Usually, when installing the editor it will ask you if you want to install the editor name command (at least TextMate did) For Instance, I use text mate, so I would do:

mate file_name

Ok, let's begin. Apache comes installed on mac os x snow leopard, but it is most likely not enabled. To enable apache, go to the apple icon on your tasks bar and select system preferences. From there, click on ‘Sharing’. Check the ‘Web Sharing’ checkbox and it will show you what your computers website addresses are. You can put websites in the ~/Sites folder (Sites directory in your home folder), that is where you will be able to bring up sites from.

Now that apache is enabled and running you can check to see if php is enabled, which by default it’s not. But you can make a text file, name it something like phpinfo.php and put this in there:

<?php phpinfo(); ?>

then put the php text file the 'Sites' directory in your home folder. Now go to the url bar in your web browser and type in:


and if php is enabled and working you should see a big information table displaying all php’s information.

However, like I said, php is not enabled by default so we have to go to the apache 'httpd.conf' file and enable it. (before you edit anything in the httpd.conf file, it’s probably a very good idea to make a copy of it, and name it something like default_httpd.conf .. you can do this by doing

cp httpd.conf default_http.conf

cp stands for copy, then you type the file you want to copy followed by either the location or filename you want to copy it to).

To do this, we need to open terminal and do this:

cd /private/etc/apache2

Type ‘ls’ (list) to see what the contents of that directory are. httpd.conf should be in there, we need to open it with a text editor. For me, this means:

mate httpd.conf

In there we will need to uncomment the line that says (it should be at the end of all the ‘load module …’ lines):

#LoadModule php5_module        libexec/apache2/

Uncomment, of course, meaning to remove the ‘#’ sign at the front of the line. Stop and restart Personal Web Sharing in System Preferences as noted above.

Go to


(or whatever you named that php file I talked about above). If all is well, you should see the table containing all the information on php in a big table.

Now apache and php are configured and enabled, ready for development!

If I made any mistakes or if there are better ways of doing something, please comment and I will change it.

Last edited by RailsRhino (2010-07-26 22:37:45)

- Ben