Install the MongoDB PHP Library
Prerequisites
The MongoDB PHP Library is a high-level abstraction for the MongoDB PHP driver. As such, you must install the mongodb extension to use the library.
Installing the MongoDB PHP Driver describes how to install the mongodb extension for PHP. Instructions for installing the driver for HHVM may be found in the Installation with HHVM article.
Procedure
Install the Library
The preferred method of installing MongoDB PHP Library is with Composer by running the following from your project root:
While not recommended, you may also manually install the package via the source tarballs attached to the GitHub releases.
Configure Autoloading
Once you have installed the library, ensure that your application
includes Composer’s autoloader. The require_once
statement should point to Composer’s autoloader, as in the following example:
Refer to Composer’s autoloading documentation for more information about setting up autoloading.
If you installed the library manually from a source tarball, you will also need to manually configure autoloading:
- Map the top-level
MongoDB\namespace to thesrc/directory using your preferred autoloader implementation. - Manually require the
src/functions.phpfile, since PHP does not yet support function autoloading.