@@ -4,55 +4,103 @@ Install the |php-library|
4
4
5
5
.. default-domain:: mongodb
6
6
7
- Prerequisites
8
- -------------
7
+ .. contents:: On this page
8
+ :local:
9
+ :backlinks: none
10
+ :depth: 2
11
+ :class: singlecol
12
+
13
+ The |php-library| is a high-level abstraction for the
14
+ `PHP driver <https://php.net/mongodb>`_ (i.e. ``mongodb`` extension). This page
15
+ will briefly explain how to install both the ``mongodb`` extension and the
16
+ |php-library|.
17
+
18
+ Installing the Extension
19
+ ------------------------
20
+
21
+ Linux, Unix, and macOS users can either
22
+ :php:`install the extension with PECL <manual/en/mongodb.installation.pecl.php>`
23
+ (recommended) or
24
+ :php:`manually compile from source <manual/en/mongodb.installation.manual.php>`.
25
+ The following command may be used to install the extension with PECL:
9
26
10
- The |php-library| is a high-level abstraction for the MongoDB PHP driver. As
11
- such, you must install the `mongodb` extension to use the library.
27
+ .. code-block:: sh
28
+
29
+ sudo pecl install mongodb
30
+
31
+ .. note::
32
+
33
+ If the build process for either installation method fails to find a TLS
34
+ library, check that the development packages (e.g. ``libssl-dev``) and
35
+ `pkg-config <https://en.wikipedia.org/wiki/Pkg-config>`_ are both installed.
36
+
37
+ Once the extension is installed, add the following line to your ``php.ini``
38
+ file:
39
+
40
+ .. code-block:: ini
12
41
13
- :php:`Installing the MongoDB PHP Driver <manual/en/mongodb.installation.php>`
14
- describes how to install the `mongodb` extension for PHP. Instructions for
15
- installing the driver for HHVM may be found in the :php:`Installation with HHVM
16
- <manual/en/mongodb.installation.hhvm>` article.
42
+ extension=mongodb.so
17
43
18
- Procedure
19
- ---------
44
+ Windows users can download precompiled binaries of the extension from
45
+ `PECL <https://pecl.php.net/package/mongodb>`_. After extracting the
46
+ ``php_mongodb.dll`` file to PHP's extension directory, add the following line to
47
+ your ``php.ini`` file:
20
48
21
- Install the Library
22
- ~~~~~~~~~~~~~~~~~~~
49
+ .. code-block:: ini
23
50
24
- The preferred method of installing |php-library| is with `Composer
25
- <https://getcomposer.org/>`_ by running the following from your project
26
- root:
51
+ extension=php_mongodb.dll
52
+
53
+ Windows binaries are available for various combinations of PHP version,
54
+ thread-safety, and architecture. Failure to select the correct binary will
55
+ result in an error attempting to load the extension DLL at runtime. Additional
56
+ considerations for Windows are discussed in the
57
+ :php:`Windows installation documentation <manual/en/mongodb.installation.windows.php>`.
58
+
59
+ .. note::
60
+
61
+ If your system has multiple versions of PHP installed, each version will have
62
+ its own ``pecl`` command and ``php.ini`` file. Additionally, PHP may also use
63
+ separate ``php.ini`` files for its web and CLI environments. If the extension
64
+ has been installed but is not available at runtime, double-check that you
65
+ have used the correct ``pecl`` command (or binary in the case of Windows) and
66
+ have modified the appropriate ``php.ini`` file(s).
67
+
68
+ Installing the Library
69
+ ----------------------
70
+
71
+ The preferred method of installing the |php-library| is with
72
+ `Composer <https://getcomposer.org/>`_ by running the following command from
73
+ your project root:
27
74
28
75
.. code-block:: sh
29
76
30
77
composer require mongodb/mongodb
31
78
32
- While not recommended, you may also manually install the package via
33
- the source tarballs attached to the `GitHub releases
34
- <https://github.com/mongodb/mongo-php-library/releases>`_.
79
+ While not recommended, you may also manually install the library using a source
80
+ archive attached to the
81
+ `GitHub releases <https://github.com/mongodb/mongo-php-library/releases>`_.
35
82
36
83
Configure Autoloading
37
84
~~~~~~~~~~~~~~~~~~~~~
38
85
39
- Once you have installed the library, ensure that your application
40
- includes Composer's autoloader. The ``require_once``
41
- statement should point to Composer's autoloader, as in the following example:
86
+ Once you have installed the library, ensure that your application includes
87
+ Composer's autoloader as in the following example:
42
88
43
89
.. code-block:: php
44
90
45
- require_once __DIR__ . "/vendor/autoload.php";
91
+ <?php
92
+
93
+ require_once __DIR__ . '/vendor/autoload.php';
46
94
47
95
Refer to Composer's `autoloading documentation
48
96
<https://getcomposer.org/doc/01-basic-usage.md#autoloading>`_ for more
49
97
information about setting up autoloading.
50
98
51
- If you installed the library manually from a source tarball , you
52
- will also need to manually configure autoloading:
99
+ If you installed the library manually from a source archive , you will need to
100
+ manually configure autoloading:
53
101
54
102
#. Map the top-level ``MongoDB\`` namespace to the ``src/`` directory
55
103
using your preferred autoloader implementation.
56
104
57
- #. Manually require the ``src/functions.php`` file, since PHP does not
58
- yet support function autoloading.
105
+ #. Manually require the ``src/functions.php`` file. This is necessary because
106
+ PHP does not support autoloading for functions .
0 commit comments