First of all, you need to make sure that PHP is set to run from MAMP, not from Apple's pre-installed instance of PHP. If you go into terminal and run:
it is possible that you'll get something like
This is the Apple's pre-installed instance of PHP, not MAMP's, so any modules you install will not take effect within MAMAP, unless you set the MAMP's php binaries to your path variable.
Open the terminal and run the following two commands:
$ echo "export PATH=/Applications/MAMP/bin/php/php5.3.29/bin:$PATH" >> ~/.profile
$ . ~/.profile
Now, if you run which php again, you should see
Now that you’re pointing to the right version of PHP within MAMP, you need to install the tools that will allow you to build your extension (extensions have to be compiled within your environment to ensure they have the proper headers)
You will need to download the sources ph PHP5.3.29 from PHP Downloads site.
Once you have downloaded the PHP5.3.29, you will need to copy it where your version of PHP is running, within a folder /include/php
You can run the following commands:
$ cd /Applications/MAMP/bin/php/php5.3.29/
$ mkdir include
$ cp -R ~/Downloads/php5.3.29 include/php
Next, you will need to run ./configure inside the php you just copied.
$ cd include/php
This will create all the needed headers for PHP.
Now, we can install the mongodb extension.
$ sudo pecl install mongo
Once mongo extension is created, you will need to add this to your php.ini file.
Using the MAMP Pro menu, go to File -> Edit Template -> PHP -> PHP 5.3.29 php.ini
In this file, you should find the section with extensions and add
Now, restart MAMP and mongo extension should be installed.
You can find a quick code to make a connection to MongoDB here: