On this page
The MongoDB PHP Library is a high-level abstraction for the
PHP driver (i.e.
mongodb extension). This page
will briefly explain how to install both the
mongodb extension and the
MongoDB PHP Library.
sudo pecl install mongodb
If the build process for either installation method fails to find a TLS
library, check that the development packages (e.g.
pkg-config are both installed.
Once the extension is installed, add the following line to your
Windows users can download precompiled binaries of the extension from its
After downloading the appropriate archive for your PHP environment, extract the
php_mongodb.dll file to PHP's extension directory and add the following line
See Installing the MongoDB PHP Driver on Windows for additional information.
The preferred method of installing the MongoDB PHP Library is with Composer by running the following command from your project root:
composer require mongodb/mongodb
Once you have installed the library, ensure that your application includes Composer's autoloader as in the following example:
require_once __DIR__ . '/vendor/autoload.php';
Refer to Composer's autoloading documentation for more information about setting up autoloading.
While not recommended, you may also manually install the library using a source archive attached to the GitHub releases. When installing the library without Composer, you must ensure that all library classes and functions are loaded for your application:
If you are using a PSR-4 autoloader, map the top-level
MongoDB\namespace to the
src/directory. If you are not using an autoloader, manually require _all_ class files found recursively within the
Regardless of whether you are using an autoloader, manually require the
src/functions.phpfile. This is necessary because PHP does not support autoloading for functions.