Manually Installing the MongoDB PHP Driver

For driver developers and people interested in the latest bugfixes, you can compile the driver from the latest source code on » Github. Run the following commands to clone and build the project:

$ git clone https://github.com/mongodb/mongo-php-driver.git
$ cd mongo-php-driver
$ git submodule sync && git submodule update --init
$ phpize
$ ./configure
$ make all -j 5
$ sudo make install

Note: By default, the driver will use bundled versions of » libbson and » libmongoc and rely on PHP to find OpenSSL (i.e. PHP_SETUP_OPENSSL). If the build process fails to find OpenSSL, check that the OpenSSL development package (e.g. libssl-dev) and » pkg-config are both installed.

The last step will report where mongodb.so has been installed, similar to:

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

Ensure that the extension_dir option in php.ini points to the directory where mongodb.so was installed. You can query the option by running:

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

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

Add the following line to your php.ini file:

extension=mongodb.so

User Contributed Notes

chatocoral at gmail dot com 18-Oct-2017 03:54
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 11-Aug-2016 06:27
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 extension=mongodb.so 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