Mac OS X 10.6 – Installing Apache2/PHP/MySQL using MacPorts

This article will be broken down into the following:

1. Install Apache2/PHP5 using MacPorts (this article)

2. Install ImageMagick and GhostScript (see article here.)

3. Install Tomcat and Solr

4. Get the Apache2/PHP5 setup working with Komodo.

5. SSL and Apache (see article here)


Steps for installing Apache2/PHP5 + MySQL on a Snow Leopard machine using MacPorts.


In my job I do a lot of different things. Mostly software demonstrations but a bit of development here and there as well. The server part of the system that our company sells is built to run on Apache(or IIS), PHP and MySQL(or SQL Server or Oracle).

When Snow Leopard came out I was faced with a set of problems:

1. I needed Apache/PHP/MySQL installed on my machine

Well, you might ask, Mac OS X comes with all that goodness pre-installed doesn’t it?

The answer to that question is yes…but…there are some other conditions that need to be met:


a. The Apple-compiled versions of the software may not meet my needs either through the version installed or through, in the case of PHP, the additional modules that our application requires.

b. Apple updates to Mac OS X can and probably will blow out any changes that I might make to the stock build. That’s not good. I like to update my software.


What about using MAMP?

MAMP is a nice choice for development. Download, install and start. Easy. However, I don’t want to use MAMP if the machine is going to be used for Production. In my case I want to replicate the production environment as closely as possible.

So, how do we go about installing new builds of Apache2, PHP5.3 with MySQL support and all the PHP extension we need?

Use MacPorts.

There are 3 steps involved here:

1. Download and install the latest version of XCode

2. Download and install MacPorts

3. Use MacPorts to install the stuff we need.


Download and install the latest version of XCode


Note that this takes a bit of space on your machine.

This step cannot be avoided.

What is happening is that by installing XCode we are getting access to the compiler that MacPorts needs to be able to compile the stuff (Apache2, PHP, etc…) we are going to be installing.

1. Go to

2. Download the latest version of XCode (comes as .dmg file that is quite large)

3. Install XCode by opening the .dmg file and running the installer. You don’t need to change any of the options that are selected.


Download and install MacPorts


1. Go to the MacPorts web site and download the latest MacPorts installer (a .dmg file) for Snow Leopard.

The web site address is:

There is a key point to note in the instructions. That is the point about the ‘selfupdate’ command. This command keeps the list of ‘portfiles’ on your machine up to date with the list of current ‘ports’ available.

After the installer is done go ahead and finish the installation.

Start the ‘Terminal’ application and type in:

sudo port -v selfupdate.

Press return. A request to enter a password will appear. Keep in mind that the ‘sudo’ command is overriding your standard privileges and allowing the Terminal command to act with your Administrator privileges.

MacPorts will update itself. Note that it writes out what it is doing in the Terminal window.


Install PHP5


In this step we are going to tell MacPorts to install PHP5 (at the time of this writing the version of PHP available via MacPorts is 5.3.2). This command will also install any dependencies that PHP5 needs. That includes, in this case, Apache2.

MacPorts will install, by default, into the /opt directory. That directory will be created at the root of your hard disk.

When you are ready enter the following commands into the Terminal window.


1. Each command is telling MacPorts to go out to a Internet location, download the necessary files to compile the app or extension and then perform the compile and install the app. Hence Internet access is required

2. Each command will list out what it is doing as it performs each step. Pay attention! Watch for errors.

3. It take some time to download and compile this stuff. Don’t get impatient.


Initial Terminal command to install PHP5


sudo port install php5


Install php5 MySQL support


sudo port install php5-mysql

sudo port install php5-sqlite


Install php5 support for other stuff. Your needs may vary.


sudo port install php5-sockets

sudo port install php5-mcrypt

sudo port install php5-mbstring

sudo port install php5-imagick

sudo port install php5-xdebug

sudo port install php5-xmlrpc

sudo port install php5-xsl

sudo port install php5-zip

sudo port install php5-soap

sudo port install php5-gd

sudo port install php5-exif

sudo port install php5-openssl

sudo port install php5-iconv