PHP 5 Runkit for MAMP 1.7.2

Mar 15 2009

Ever tried to get PHP's Runkit PECL extension running on the popular MAMP stack for Mac OS X? If you have tried, you will understand why it is difficult. There are two roadblocks that must be overcome before Runkit can be installed.

The first has to do with MAMP itself. While MAMP provides most of the tools that a web developer needs, it is generally incapable of dealing with PECL builds. The reason for this is simple: MAMP does not ship with header files for PHP. That means that extensions built from C source files cannot successfully compile. That is a problem.

The second difficulty has to do with Runkit, which (being basically feature complete) hasn't undergone a major revision in a couple of years. The official released version, in fact, will not run on PHP 5.2. Yes, that is the version that ships with MAMP. To get the fixed version, you will need to check out the latest source code from's CVS repository and build it yourself.

Recently, I found a situation that demanded Runkit. (Okay, it might have been a contrived situation.) To accomplish the goal of my project, I built Runkit from source. If you want it, the file is attached at the end of this post. <!--break--> Here is how I worked around the issues above in order to build Runkit for MAMP's PHP 5 installation.

  • While MAMP doesn't include PHP 5.2 header files, XCode does. So I created a symbolic link from /Developer/SDKs/MacOSX10.5.sdk/usr/include/ to /Applications/MAMP/bin/php5/lib/php/include.
  • I checked out the source of Runkit from CVS and built it using configure and make.
  • From there, I simply copied the module into the /Applications/MAMP/bin/php5/lib/php/extensions directory. (If you download the attached file, you will need to do this step.).

Since I don't want runkit added every time I run a script, I use the dl() function inside of my PHP code to load Runkit when I need it. (See the not below for my explanation of why I do this instead of loading Runkit from the PHP ini file.)

I don't want to compile. How do I install the file at the end of this post?

To install the shared object as a PHP extension, you will want to do the following:

  • copied the module into the /Applications/MAMP/bin/php5/lib/php/extensions directory.
  • In your code, use dl('') to dynamically load runkit.

This last step is (IMHO) better than adding a directive to your php.ini file because it will only provide access to runkit when you declare that you need it. Given runkit's... um... potentially disruptive capabilities, this is probably good practice. If you must, though, you can add to the list of extensions automatically loaded. This is done by adding a line like this to the end of your php.ini file:


You will need to restart MAMP before the changes will take place.

comments powered by Disqus