Posted by & filed under NoSQL, OS X, PHP.

There is a summary at the end of this post to skip all of my debugging. Scroll to the end to skip all of this rambling.

I was trying to get MongoDB support working in the PHP provided by MAMP Pro. I issued the PECL command to get it installed and was greeted with the following error:

tlhunter@macbook:/Volumes/Server $ sudo pecl install mongo
downloading mongo-1.2.7.tgz ...
Starting to download mongo-1.2.7.tgz (84,677 bytes)
....................done: 84,677 bytes
36 source files, building
running: phpize
grep: /Applications/MAMP/bin/php/php5.3.6/include/php/main/php.h: No such file or directory
grep: /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend_modules.h: No such file or directory
grep: /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
... Output Truncated
/private/tmp/pear/install/mongo/php_mongo.h:564: error: declaration for parameter ‘default_host’ but no such parameter
/private/tmp/pear/install/mongo/php_mongo.h:563: error: declaration for parameter ‘allow_persistent’ but no such parameter
/private/tmp/pear/install/mongo/php_mongo.h:562: error: declaration for parameter ‘auto_reconnect’ but no such parameter
/private/tmp/pear/install/mongo/php_mongo.c:344: error: expected ‘{’ at end of input
lipo: can't figure out the architecture type of: /var/tmp//ccbF5uEi.out
make: *** [php_mongo.lo] Error 1
ERROR: `make' failed

It turns out MAMP doesn’t ship with a bunch of the PHP sources (makes sense, most people don’t need them and it makes the download a lot bigger). To get the PHP sources required to build MongoDB using PECL, you can visit the MAMP Download Page, scroll down to Source Code, and download the components file (in this case it was named You can also grab it from their SourceForge page.

Once you get that file you can decompress it to a temporary directory. It is full of a ton of archives. You’ll want to find the PHP archive for the version you’re using (I’m using 5.3.6). Extract this archive. You’ll want to move the files from this archive to the right directory, as specified in the error message. So, you’ll want to navigate to the following directory:


And then make a folder in there called includes and a folder in there called php. Then, move the files from the php archive into this folder.

Unfortunately, shit still don’t work. Issuing the PECL command again issues these errors now:

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/libtool --mode=compile cc -I./util -I. -I/private/tmp/pear/install/mongo -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/include -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/main -I/private/tmp/pear/install/mongo -I/Applications/MAMP/bin/php/php5.3.6/include/php -I/Applications/MAMP/bin/php/php5.3.6/include/php/main -I/Applications/MAMP/bin/php/php5.3.6/include/php/TSRM -I/Applications/MAMP/bin/php/php5.3.6/include/php/Zend -I/Applications/MAMP/bin/php/php5.3.6/include/php/ext -I/Applications/MAMP/bin/php/php5.3.6/include/php/ext/date/lib -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/util -I/private/tmp/pear/install/mongo/util -DHAVE_CONFIG_H -g -O2 -arch i386 -arch x86_64 -mmacosx-version-min=10.5 -c /private/tmp/pear/install/mongo/php_mongo.c -o php_mongo.lo
mkdir .libs
 cc -I./util -I. -I/private/tmp/pear/install/mongo -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/include -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/main -I/private/tmp/pear/install/mongo -I/Applications/MAMP/bin/php/php5.3.6/include/php -I/Applications/MAMP/bin/php/php5.3.6/include/php/main -I/Applications/MAMP/bin/php/php5.3.6/include/php/TSRM -I/Applications/MAMP/bin/php/php5.3.6/include/php/Zend -I/Applications/MAMP/bin/php/php5.3.6/include/php/ext -I/Applications/MAMP/bin/php/php5.3.6/include/php/ext/date/lib -I/private/tmp/pear/install/pear-build-rootw1St0p/mongo-1.2.7/util -I/private/tmp/pear/install/mongo/util -DHAVE_CONFIG_H -g -O2 -arch i386 -arch x86_64 -mmacosx-version-min=10.5 -c /private/tmp/pear/install/mongo/php_mongo.c -fno-common -DPIC -o .libs/php_mongo.o
In file included from /Applications/MAMP/bin/php/php5.3.6/include/php/main/php.h:34,
 from /private/tmp/pear/install/mongo/php_mongo.c:22:
/Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend.h:51:26: error: zend_config.h: No such file or directory
In file included from /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend_alloc.h:27,
 from /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend.h:237,
 from /Applications/MAMP/bin/php/php5.3.6/include/php/main/php.h:34,
 from /private/tmp/pear/install/mongo/php_mongo.c:22:
/Applications/MAMP/bin/php/php5.3.6/include/php/Zend/../TSRM/TSRM.h:20:26: error: tsrm_config.h: No such file or directory
In file included from /Applications/MAMP/bin/php/php5.3.6/include/php/Zend/zend.h:237,
 from /Applications/MAMP/bin/php/php5.3.6/include/php/main/php.h:34,
 from /private/tmp/pear/install/mongo/php_mongo.c:22:

It is at this point that we curse the antiquated make system and the dependency hell developers put us though. These errors appear to have something to do with libtool or tsrm or zend or who knows what the hell is going on.

If you know how to fix these issues, please leave a comment below and let me know what you did!

I got annoyed and started looking into pure PHP drivers for MongoDB. These libraries don’t require a binary to work and will work with any platform. They aren’t written in C, so they are theoretically slower, but since MongoDB uses such a simple interface, I doubt this will make the application much slower.

BLAST! It turns out those aren’t actually pure PHP drivers, they depend on the binary still. This angers the humble PHP developer. So, we get annoyed some more and look for the binary and download it, and copy it into the extensions folder used by MAMP:


We also add to the list of extensions in our PHP.ini file:

/Library/Application Support/appsolute/MAMP PRO/conf/php.ini:~539

And then we reboot. Only to find out that nothing happened. Turns out MAMP deletes and rebuilds this file each time it restarts. A quick google search reveals the PHP file it uses before being rebuild is located here, so we edit that one:


We do a reset of the server and… Still nothing works. A google search reveals the best way to edit the php.ini file is to go to File > Edit Template > PHP > PHP 5.3.6 php.ini. So we edit that file and add the line near the list of extensions (line 541). Then, we restart the server and OH MY GOD IT WORKED!


That was a lot of hoops to jump through to get this working. Here’s the condensed version:

  • Download and extract the pre-compiled binary PHP extension
  • Move file to /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/
  • MAMP Pro > File > Edit Template > PHP > PHP 5.3.6 php.ini | Line 541 add
  • Restart MAMP Services

Thomas Hunter II

Thomas is passionate about technology and building products. A web design business created while attending college slowly evolved into a brick and mortar on Main St. of his small Midwestern hometown. His desire for fame and fortune led to the co-founding of a Y Combinator startup and a life in California.

15 Responses to “Getting the PHP MongoDB driver installed with MAMP on OS X”

  1. Sven Loth

    Hi Thomas, you must run ./configure in …MAMP/bin/php/php5.3.6/include/php BEFORE you start compiling any modules. Otherwise header files are missing.

  2. Will

    *** The folder should be called ‘include’ , not ‘includes’. This tripped me up for a bit.

  3. Gautam

    I’ve been trying to add mongodb driver since last night. Searched google for so many times but couldn’t find any problem.
    Your post has finally saved the day! Thanks mate!!

  4. Rob Woodall

    Thank you so much for this, struggled all morning to get it up and running. Dare I say it was much easier on my server and my *ahem* windows box


Leave a Reply

Your email address will not be published. Required fields are marked *