oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

PHP on Mac OS X

by Jay Greenspan and Apple Developer Connection

The BSD underpinnings of Mac OS X allow PHP to run as an Apache module in its native Unix environment. Using Mac OS X, programmers will see the same stability and extensibility from PHP they have seen in their production servers that run BSD, Linux, Solaris, and other Unix variants.

Like all Unix variants, Mac OS X has its quirks. It's also a young OS, and not all open-source or Unix software projects have had time to test their programs on the Mac and make the necessary alterations. Most major packages that work with PHP can be installed with only minimal difficulty on Mac OS X. There's little doubt that just about everything will eventually work on Mac OS X. Most the changes will be minor, and, as many have pointed out, by the end of this year Mac OS X will be the most widely distributed Unix system on the planet.

Default settings

After the initial installation of Mac OS X, a cursory view of the file system will reveal that some PHP components are pre-installed. Apache is initially configured to allow for DSO modules. These modules provide specific functionality and are loaded into Apache as the Web server is started. A PHP 4 module ( is installed by default in /usr/libexec/httpd, along with a series of other DSO modules. However, this module does not function properly and you will need to re-install PHP in order to get it working.

Note: Mac OS X does not yet support dynamic loading of modules (using the dl() function).

Comment on this articleBringing the power of PHP to the Mac OS X platform has some tremendous implications. What are the possibilities as you see them?
Post your comments

Configuration tips

The following listings show some suggested flags and configuration tweaks that may help you in the process of configuring and installing PHP on Mac OS X. Additionally, there is a rundown of modules that have been successfully built on Mac OS X. The list is not exhaustive; it represents some of the more popular modules that are used with PHP. If you have successfully compiled an additional module, please let us know.

This article focuses on PHP 4.0.6. If you have an earlier version, you should go to and get the latest source.

Suggested flags

The Darwin file system is arranged somewhat differently than some other Unix variants. Running the configure command with the following flags will help keep your system properly organized.

--prefix=/usr \
--sysconfdir=/etc \ 
--localstatedir=/var \ 
--mandir=/usr/share/man \

To have PHP automatically installed as a DSO module that will be available as soon as you restart Apache, use

--with-apxs \

In PHP 4.06, zlib, which is automatically detected on many other systems, must be explicitly included in the configure stage with the --with-zlib flag. If this is not included in your configure command, certain libraries, including MySQL client libraries, will not function properly and Apache will not start. So include:

--with-zlib \

Also, in PHP 4.0.6, PEAR does not install properly, so include the flag:

--disable-pear \

PHP modules

As mentioned earlier, most modules should work on Mac OS X with a few small changes. If you find that a module you wish to install gives an error stating that the configure script cannot recognize the platform, you should update the config.guess and config.sub files that came with the package. Recent versions of these files can be found in /usr/libexec.


There have been some reported problems with MySQL version 3.23.39, but these are easily overcome. If you have upgraded Mac OS X to version 10.0.4, it may be necessary to run the make processes as root. Normally in Mac OS X, one runs processes as root by using the sudo command. However, in the case of MySQL 3.23.39, it may be necessary to enable the root user (by using sudo su) and run the make process while logged in as root.

Before you enable root, make sure that MySQL cannot be installed by a non-root user. If you are having trouble, you may opt to use a pre-compiled version of MySQL. This package has a nice installer that will get you up and running with MySQL very quickly.

If you need transaction-safe tables with MySQL, you can configure MySQL to use InnoDB tables. BerkeleyDB tables do not seem to function on Mac OS X at this point.

To use the most recent client libraries with PHP, you should include the path to your PHP installation. Also, make sure your installation of PHP will use zlib.

--with-mysql=[DIR] \


PostgreSQL version 7.1.2 also compiles with little difficulty on Mac OS X. The only bug occurs during the make install process. If make install fails, simply run sudo make install a second time. This will install the files properly.

Before compiling PostgreSQL support into PHP, I had to run the following command:

sudo ranlib /usr/local/libpg.a

This should enable you to include PostgreSQL in your configure script.


Pages: 1, 2

Next Pagearrow