To install the MongoDB PHP driver on macOS (OS X El Capitan), you can use Homebrew to quickly and easily install the required dependencies and then compile the driver from source. Follow these steps:

  1. Install Homebrew (if not already installed): Open the Terminal and paste the following command to install Homebrew:

    /bin/bash -c "$(curl -fsSL"
  2. Install the required dependencies: Run the following commands to install the required dependencies for compiling the MongoDB PHP driver:

    brew tap mongodb/brew brew install autoconf openssl
  3. Install the MongoDB PHP driver: Now, you can use pecl (PHP Extension Community Library) to install the MongoDB PHP driver. In the Terminal, run the following command:

    pecl install mongodb

    If prompted for the PHP executable path, enter the path where your PHP executable is installed. It's typically located in /usr/bin/php.

  4. Enable the MongoDB PHP extension: Add the MongoDB PHP extension to your php.ini file. Open the Terminal and enter the following command to edit the php.ini file:

    sudo nano /etc/php.ini

    Add the following line to the php.ini file:


    Save the changes and exit the editor (press Ctrl+O to save, Ctrl+X to exit).

  5. Restart the web server: Restart your web server to apply the changes. If you're using Apache, you can restart it with:

    sudo apachectl restart
  6. Verify the MongoDB PHP driver installation: To check if the MongoDB PHP driver is installed and enabled, you can create a PHP script with the following content:

    <?php phpinfo();

    Save the file as info.php in your web server's root directory. Then, access the file in your web browser (http://localhost/info.php) and search for "mongodb" to ensure that the extension is loaded and enabled.

That's it! The MongoDB PHP driver should now be installed and enabled on your macOS (OS X El Capitan) system. You can start using MongoDB in your PHP applications.

Have questions or queries?
Get in Touch