Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

杨树贤 / ucenter

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • ucenter
  • ..
  • tutorial
  • install-php-library.txt
install-php-library.txt 3.45 KB
杨树贤's avatar
初始化项目
130b5f67
 
杨树贤 committed a year ago
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
=========================
Install the |php-library|
=========================

.. default-domain:: mongodb

.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 2
   :class: singlecol

The |php-library| is a high-level abstraction for the
`PHP driver <https://php.net/mongodb>`_ (i.e. ``mongodb`` extension). This page
will briefly explain how to install both the ``mongodb`` extension and the
|php-library|.

Installing the Extension
------------------------

Linux, Unix, and macOS users can either
:php:`install the extension with PECL <manual/en/mongodb.installation.pecl.php>`
(recommended) or
:php:`manually compile from source <manual/en/mongodb.installation.manual.php>`.
The following command may be used to install the extension with PECL:

.. code-block:: sh

   sudo pecl install mongodb

.. note::

   If the build process for either installation method fails to find a TLS
   library, check that the development packages (e.g. ``libssl-dev``) and
   `pkg-config <https://en.wikipedia.org/wiki/Pkg-config>`_ are both installed.

Once the extension is installed, add the following line to your ``php.ini``
file:

.. code-block:: ini

   extension=mongodb.so

Windows users can download precompiled binaries of the extension from
`PECL <https://pecl.php.net/package/mongodb>`_. After extracting the
``php_mongodb.dll`` file to PHP's extension directory, add the following line to
your ``php.ini`` file:

.. code-block:: ini

   extension=php_mongodb.dll

Windows binaries are available for various combinations of PHP version,
thread-safety, and architecture. Failure to select the correct binary will
result in an error attempting to load the extension DLL at runtime. Additional
considerations for Windows are discussed in the
:php:`Windows installation documentation <manual/en/mongodb.installation.windows.php>`.

.. note::

   If your system has multiple versions of PHP installed, each version will have
   its own ``pecl`` command and ``php.ini`` file. Additionally, PHP may also use
   separate ``php.ini`` files for its web and CLI environments. If the extension
   has been installed but is not available at runtime, double-check that you
   have used the correct ``pecl`` command (or binary in the case of Windows) and
   have modified the appropriate ``php.ini`` file(s).

Installing the Library
----------------------

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

.. code-block:: sh

   composer require mongodb/mongodb

While not recommended, you may also manually install the library using a source
archive 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 as in the following example:

.. code-block:: php

   <?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 archive, you will 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. This is necessary because
   PHP does not support autoloading for functions.