&reftitle.install;
Installing the MongoDB PHP Driver with PECL
&pecl.info;
&url.pecl.package;mongodb
Linux, Unix, and macOS users may run the following command to install the
driver:
If your system has multiple version of PHP installed (e.g. macOS default,
Homebrew, XAMPP), note that that each
version of PHP has its own pecl
command and &php.ini; file.
Installing the driver via PECL will use bundled versions of
libbson and
libmongoc and attempt to
automatically configure them.
If the build process fails to find an SSL library, check that the
development packages (e.g. libssl-dev) and
pkg-config are both
installed. If that does not resolve the problem, consider using the
manual installation
process.
Finally, add the following line to your &php.ini; file:
Installing the MongoDB PHP Driver on macOS with Homebrew
Homebrew 1.5.0
deprecated the Homebrew/php tap
and removed formulae for individual PHP extensions. Going forward, macOS
users are advised to install the
php formula
and follow the standard
PECL installation instructions
using the pecl command provided by the
Homebrew PHP installation.
Installing the MongoDB PHP Driver on Windows
Precompiled binaries for each release are available from
PECL for a variety of
combinations of versions, thread safety, and VC libraries. Extract the
archive and put php_mongodb.dll in your PHP extension
directory ("ext" by default).
Add the following line to your &php.ini; file:
Manually Installing the MongoDB PHP Driver
For driver developers and people interested in the latest bugfixes, you can
compile the driver from the latest source code on
Github. Run the following
commands to clone and build the project:
If your system has multiple version of PHP installed (e.g. macOS default
and XAMPP), note
that each version of PHP has its own
phpize command and &php.ini; file.
By default, the driver will use bundled versions of
libbson and
libmongoc and attempt to
configure them on its own. If libbson and libmongoc are already installed as
system libraries, you can instruct the driver to utilize them by specifying
--with-libbson=yes --with--libmongoc=yes as arguments to
configure.
For a complete list of configure options, run
configure --help.
When using bundled versions of libbson and libmongoc, the driver will also
attempt to select an SSL library according to the
--with-mongodb-ssl option for
configure. The default value is
--with-mongodb-ssl=auto, which will search for Secure
Transport (macOS only), OpenSSL, and LibreSSL, in that order. Additionally,
you may specify openssl, libressl, or
darwin to force selection of a particular library,
respectively.
If the build process fails to find an SSL library, check that the
development packages (e.g. libssl-dev) and
pkg-config are both
installed.
When using Homebrew on macOS, it is common for a system to have multiple
versions of OpenSSL installed. To ensure that the desired version of OpenSSL
is selected, the PKG_CONFIG_PATH environment variable may
be used to control the search path for pkg-config. If
pkg-config is not used, configure also
supports a --with-openssl-dir=DIR argument, which can be
used to specify a manual search path (for OpenSSL only).
The final build step, make install, will report where
mongodb.so has been installed, similar to:
Ensure that the extension_dir option
in &php.ini; points to the directory where mongodb.so
was installed. You can query for the option by running:
/usr/lib/php/extensions/debug-non-zts-20151012 =>
/usr/lib/php/extensions/debug-non-zts-20151012
]]>
If the directories differ, either change
extension_dir in &php.ini; or
manually move mongodb.so to the correct directory.
Finally, add the following line to your &php.ini; file: