========================= Install the |php-library| ========================= .. default-domain:: mongodb 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 |php-library|: .. code-block:: sh pecl install mongodb echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` Instructions for installing the `mongodb` extension on HHVM may be found in the :php:`Installation with HHVM ` article in the driver documentation. Procedure --------- Install the Library ~~~~~~~~~~~~~~~~~~~ The preferred method of installing |php-library| is with `Composer `_ by running the following from your project root: .. code-block:: sh composer require "mongodb/mongodb=^1.0.0" 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: .. code-block:: php require_once __DIR__ . "/vendor/autoload.php"; 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 the ``src/`` directory using your preferred autoloader implementation. #. Manually require the ``src/functions.php`` file, since PHP does not yet support function autoloading.