Installing the MongoDB PHP Driver on OSX with Homebrew

If you are using » Homebrew, the PHP tap includes formulae for installing the driver on various PHP versions.

  • php54-mongodb
  • php55-mongodb
  • php56-mongodb
  • php70-mongodb

For example, you might install the driver for PHP 7.0 using the following command:

$ brew install php70-mongodb

User Contributed Notes

cristian dot carreno dot g at gmail dot com 23-Sep-2017 11:24
For OS Sierra 10.12.6

PHP 5.6

brew tap homebrew/php
brew install php56-mongodb
extension="/usr/local/opt/php56-mongodb/mongodb.so"
simon at programujem dot eu 12-Apr-2017 05:56
The mongodb extension is also available for PHP 7.1, you can install it using similar command:

brew install php71-mongodb
haxpor at gmail dot com 02-Mar-2017 11:29
No only just you install it via brew for correct version of php installed on your machine.

You have to set extension in php.ini too.

In case of macOS and php 5.6 installed.
I have to set

extension="/usr/local/opt/php56-mongo/mongo.so"

The correct path will show mongodb loaded on phpinfo.
amit dot clavax at gmail dot com 24-Nov-2016 03:06
Below command work for me mac sierra os
brew install php55-mongodb
givemeanthony at outlook dot com 04-Sep-2016 06:05
You must first tap the PHP formula repository from terminal like so

    brew tap homebrew/php

in order to install PHP extensions like MongoDB via Homebrew.
After tapping the formula repository, install the MongoDB extension

    brew install phpxx-mongodb

where xx is the version number.
avtrulzz at yahoo dot co dot in 03-Sep-2016 07:07
The correct command for installation is using homebrew is
brew install homebrew/php/phpxx-mongodb

For ex. to install the driver for php5.6 use :
brew install homebrew/php/php55-mongodb