Skip to content

Commit add2c8d

Browse files
committed
PHPLIB-523 Document install steps for extension
This adds inline instructions for installing the extension in lieu of sending readers to PHP.net.
1 parent 6456b89 commit add2c8d

File tree

1 file changed

+74
-26
lines changed

1 file changed

+74
-26
lines changed

docs/tutorial/install-php-library.txt

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,103 @@ Install the |php-library|
44

55
.. default-domain:: mongodb
66

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:
926

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
1241

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
1743

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:
2048

21-
Install the Library
22-
~~~~~~~~~~~~~~~~~~~
49+
.. code-block:: ini
2350

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:
2774

2875
.. code-block:: sh
2976

3077
composer require mongodb/mongodb
3178

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>`_.
3582

3683
Configure Autoloading
3784
~~~~~~~~~~~~~~~~~~~~~
3885

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:
4288

4389
.. code-block:: php
4490

45-
require_once __DIR__ . "/vendor/autoload.php";
91+
<?php
92+
93+
require_once __DIR__ . '/vendor/autoload.php';
4694

4795
Refer to Composer's `autoloading documentation
4896
<https://getcomposer.org/doc/01-basic-usage.md#autoloading>`_ for more
4997
information about setting up autoloading.
5098

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:
53101

54102
#. Map the top-level ``MongoDB\`` namespace to the ``src/`` directory
55103
using your preferred autoloader implementation.
56104

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

Comments
 (0)