MAMP - Install MongoDB

Please note: replace 7.x.x with your PHP version.

Edit .bash_profile

This is important because it tells pecl in which PHP version the mongodb module should be added.

nano ~/.bash_profile
alias php="/Applications/MAMP/bin/php/php7.x.x /bin/php"
export PATH="/Applications/MAMP/bin/php/php7.x.x /bin:$PATH"

Apply the changes in .bash_profile

source ~/.bash_profile

Install MongoDB via PECL

pecl install mongodb
Installing '/Applications/MAMP/bin/php/php7.x.x/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so'

Check if the PHP version is correct.

Add the mongodb extenstion to php.ini

FileEdit TemplatePHP (php.ini)7.x.x

; Extensions
extension=mongodb.so

Restart MAMP, and check phpinfo

mongodb.png

PHP CLI

Please note: PHP CLI could run on a different version then Apache.

php --ini

Loaded Configuration File: /Applications/MAMP/bin/php/php7.x.x/conf/php.ini

Add the mongodb extenstion to php.ini

nano /Applications/MAMP/bin/php/php7.x.x/conf/php.ini
; Extensions
extension=mongodb.so

Restart MAMP, and check if the mongodb module is loaded

php -m | grep mongodb