<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Manually Installing the MongoDB PHP Driver</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb.installation.windows.html">Installing the MongoDB PHP Driver on Windows</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb.configuration.html">Runtime Configuration</a></div> <div class="up"><a href="mongodb.installation.html">Installation</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongodb.installation.manual" class="section"> <h2 class="title">Manually Installing the MongoDB PHP Driver</h2> <p class="para"> For driver developers and people interested in the latest bugfixes, you can compile the driver from the latest source code on <a href="https://github.com/mongodb/mongo-php-driver-legacy" class="link external">» Github</a>. Run the following commands to clone and build the project: <div class="example-contents"> <div class="shellcode"><pre class="shellcode">$ git clone https://github.com/mongodb/mongo-php-driver.git $ cd mongo-php-driver $ git submodule update --init $ phpize $ ./configure $ make all $ sudo make install</pre> </div> </div> </p> <p class="para"> If your system has multiple version of PHP installed (e.g. macOS default <em class="emphasis">and</em> <a href="https://www.apachefriends.org/" class="link external">» XAMPP</a>), note that each version of PHP has its own <a href="install.pecl.phpize.html" class="link">phpize</a> command and <var class="filename">php.ini</var> file. </p> <p class="para"> By default, the driver will use bundled versions of <a href="https://github.com/mongodb/libbson" class="link external">» libbson</a> and <a href="https://github.com/mongodb/mongo-c-driver" class="link external">» libmongoc</a> 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 <em>--with-libbson=yes --with--libmongoc=yes</em> as arguments to <em>configure</em>. </p> <p class="para"> For a complete list of <em>configure</em> options, run <strong class="command">configure --help</strong>. </p> <p class="para"> When using bundled versions of libbson and libmongoc, the driver will also attempt to select an SSL library according to the <em>--with-mongodb-ssl</em> option for <em>configure</em>. The default value is <em>--with-mongodb-ssl=auto</em>, which will search for Secure Transport (macOS only), OpenSSL, and LibreSSL, in that order. Additionally, you may specify <em>openssl</em>, <em>libressl</em>, or <em>darwin</em> to force selection of a particular library, respectively. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> If the build process fails to find an SSL library, check that the development packages (e.g. <em>libssl-dev</em>) and <a href="https://en.wikipedia.org/wiki/Pkg-config" class="link external">» pkg-config</a> are both installed. </p> <p class="para"> 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 <em>PKG_CONFIG_PATH</em> environment variable may be used to control the search path for <em>pkg-config</em>. If <em>pkg-config</em> is not used, <em>configure</em> also supports a <em>--with-openssl-dir=DIR</em> argument, which can be used to specify a manual search path (for OpenSSL only). </p> </p></blockquote> <p class="para"> The final build step, <strong class="command">make install</strong>, will report where <var class="filename">mongodb.so</var> has been installed, similar to: <div class="example-contents"> <div class="txtcode"><pre class="txtcode">Installing shared extensions: /usr/lib/php/extensions/debug-non-zts-20151012/</pre> </div> </div> </p> <p class="para"> Ensure that the <a href="ini.core.html#ini.extension-dir" class="link">extension_dir</a> option in <var class="filename">php.ini</var> points to the directory where <var class="filename">mongodb.so</var> was installed. You can query for the option by running: <div class="example-contents"> <div class="shellcode"><pre class="shellcode">$ php -i | grep extension_dir extension_dir => /usr/lib/php/extensions/debug-non-zts-20151012 => /usr/lib/php/extensions/debug-non-zts-20151012</pre> </div> </div> </p> <p class="para"> If the directories differ, either change <a href="ini.core.html#ini.extension-dir" class="link">extension_dir</a> in <var class="filename">php.ini</var> or manually move <var class="filename">mongodb.so</var> to the correct directory. </p> <p class="para"> Finally, add the following line to your <var class="filename">php.ini</var> file: <div class="example-contents"> <div class="inicode"><pre class="inicode">extension=mongodb.so</pre> </div> </div> </p> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb.installation.windows.html">Installing the MongoDB PHP Driver on Windows</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb.configuration.html">Runtime Configuration</a></div> <div class="up"><a href="mongodb.installation.html">Installation</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>