Building the MongoDB PHP Driver from source

For developers and users interested in the latest bugfixes, the extension may be compiled from the latest source code on » Github. Run the following commands to clone and build the project:

$ git clone
$ cd mongo-php-driver
$ git submodule update --init
$ phpize
$ ./configure
$ make all
$ sudo make install

On systems with multiple version of PHP installed (e.g. macOS default, Homebrew, » XAMPP), each version of PHP will have its own phpize command and php.ini file(s). Additionally, each PHP environments (e.g. CLI, web) may use separate php.ini files.

By default, the extension will use bundled versions of » libbson, » libmongoc, and » libmongocrypt and attempt to configure them automatically. If these libraries are already installed as system libraries, the extension can utilize them by specifying --with-mongodb-system-libs=yes as an option to configure.

For a complete list of configure options, run configure --help.

When using bundled versions of libmongoc and libmongocrypt, the extension will also attempt to select an SSL library according to the --with-mongodb-ssl configure option. As of extension version 1.17.0, OpenSSL is always preferred by default. Previously, Secure Transport was the default on macOS and OpenSSL was the default on all other platforms.


If the build process fails to find an SSL library, check that the development packages (e.g. libssl-dev) and » pkg-config are both installed.

When using Homebrew on macOS, it is common for a system to have multiple versions of OpenSSL installed. To ensure that the desired version of OpenSSL is selected, the PKG_CONFIG_PATH environment variable may be used to control the search path for pkg-config. If pkg-config is not used, configure also supports a --with-openssl-dir=DIR argument, which can be used to specify a manual search path (for OpenSSL only).

The final build step, make install, will report where has been installed, similar to:

Installing shared extensions:     /usr/lib/php/extensions/debug-non-zts-20220829/

Ensure that the extension_dir option in php.ini points to the directory where was installed. The option may be queried by running:

$ php -i | grep extension_dir
  extension_dir => /usr/lib/php/extensions/debug-non-zts-20220829 =>

If the directories differ, either change extension_dir in php.ini or manually move to the correct directory.

Finally, add the following line to the php.ini file for each environment that will need to use the extension:

add a note

User Contributed Notes 3 notes

chatocoral at gmail dot com
6 years ago
You think this is to complicated? You use Ubuntu 14 or 16? use this:

sudo apt-get install php-mongodb

This installs everything you need to use MongoDB inside PHP.

Don't stop using MongoDB, is the best that will happen to you.

You're Welcome.
fgm at osinet dot fr
7 years ago
a) If your git version is not recent enough, as can happen e.g. on Ubuntu 12.04 LTS, git submodule --init won't exist
In that case use:

git submodule init
git submodule update

b) make install does not create a mongodb.conf configuration file to support the debian/ubuntu PHP versions phpenmod/phpdismod commands. To have them work:

- do not add the line to php.ini
- add it to a mongodb.ini file in the PHP mods-available directory
- the commands will then work for this extension

c) if you have multiple versions of PHP on a system such as b), the phpenmod/phpdismod commands may fail if the extension is not built for the default PHP CLI version. To have it be enabled for a specific version, use the -v argument, like

phpenmod -v php7.1 mongodb
Anisur Rahman (anisur2805 at gmail dot com)
3 years ago
After installing mongodb, in terminal there are couple of error ex.

PHP Warning: PHP Startup: Unable to load dynamic library '' (tried: C:\xampp\php\ext\ (The specified module could not be found.), C:\xampp\php\ext\ (The specified module could not be found.)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '' (tried: C:\xampp\php\ext\ (The specified module could not be found.), C:\xampp\php\ext\ (The specified module could not be found.)) in Unknown on line 0

1. If you include mongodb extension in php.ini file first remove that
2. Goto your php path inside Xampp and create an file called mongodb.ini and pest this below line, see ss -

This solution works in windows 10, php 7.4 version
To Top