install-php-library.txt 1.79 KB
Newer Older
1 2 3 4 5 6 7 8 9
=========================
Install the |php-library|
=========================

.. default-domain:: mongodb

Prerequisites
-------------

10 11
The |php-library| is a high-level abstraction for the MongoDB PHP driver. As
such, you must install the `mongodb` extension to use the library.
12

13 14 15 16
:php:`Installing the MongoDB PHP Driver <manual/en/mongodb.installation.php>`
describes how to install the `mongodb` extension for PHP. Instructions for
installing the driver for HHVM may be found in the :php:`Installation with HHVM
<manual/en/mongodb.installation.hhvm>` article.
17 18 19 20 21 22 23 24 25 26 27 28 29

Procedure
---------

Install the Library
~~~~~~~~~~~~~~~~~~~

The preferred method of installing |php-library| is with `Composer
<https://getcomposer.org/>`_ by running the following from your project
root:

.. code-block:: sh

30
   composer require mongodb/mongodb
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

While not recommended, you may also manually install the package via
the source tarballs attached to the `GitHub releases
<https://github.com/mongodb/mongo-php-library/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
<https://getcomposer.org/doc/01-basic-usage.md#autoloading>`_ 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.