Installation
This extension is deprecated. Instead, the MongoDB extension should be used.
The MongoDB PHP driver should work on nearly any system: Windows, macOS, Unix, and Linux; little- and big-endian machines; 32- and 64-bit machines; PHP 5.3 through 5.6 (versions prior to 1.6 also support PHP 5.2).
This » PECL extension is not bundled with PHP.
- Manual Installation
- Installing on *NIX
- Installing on Windows
- macOS
- Gentoo
- Red Hat
- Third-Party Installation Instructions
Manual Installation
For driver developers and people interested in the latest bugfixes, you can compile the driver from the latest source code on » Github. Go to Github and click the "download" button. Then run:
$ tar zxvf mongo-php-driver-legacy-<commit_id>.tar.gz $ cd mongo-php-driver-legacy-<commit_id> $ phpize $ ./configure $ make all $ sudo make install
Make the following changes to php.ini:
-
Make sure the extension_dir variable is pointing to the directory containing mongo.so. The build will display where it is installing the PHP driver with output that looks something like:
Installing '/usr/lib/php/extensions/no-debug-non-zts-20060613/mongo.so'
$ php -i | grep extension_dir extension_dir => /usr/lib/php/extensions/no-debug-non-zts-20060613 => /usr/lib/php/extensions/no-debug-non-zts-20060613
-
To load the extension on PHP startup, add a line:
extension=mongo.so
Installing on *NIX
Run:
$ sudo pecl install mongo
Add the following line to your php.ini file:
extension=mongo.so
If pecl runs out of memory while installing, make sure memory_limit in php.ini is set to at least 128MB.
Installing on Windows
Precompiled binaries for each release are available from » PECL for a variety of combinations of versions, thread safety, and VC libraries. Unzip the archive and put php_mongo.dll in your PHP extension directory ("ext" by default).
Add the following line to your php.ini file:
extension=php_mongo.dll
Note: Additional DLL dependencies for Windows Users
In order for this extension to work, there are DLL files that must be available to the Windows system PATH. For information on how to do this, see the FAQ entitled "How do I add my PHP directory to the PATH on Windows". Although copying DLL files from the PHP folder into the Windows system directory also works (because the system directory is by default in the system's PATH), this is not recommended. This extension requires the following files to be in the PATH: libsasl.dll
macOS
In most cases installing from PECL is the easiest way:
$ sudo pecl install mongo
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.
Note: Xcode dependency for compiling on macOS
Compiling the driver on macOS will require Xcode developer tools, which may be installed with
xcode-select --install
. If that command is not available, you may first need to install the » Command Line Tools package.
Gentoo
Gentoo has a package for the PHP PECL driver called dev-php/pecl-mongo, which can be installed with:
$ sudo emerge -va dev-php/pecl-mongo
If you use PECL, you may get an error that libtool is the wrong version. Compiling from source you'll need to run aclocal and autoconf.
$ phpize $ aclocal $ autoconf $ ./configure $ make $ sudo make install
Red Hat
This includes Fedora and CentOS.
The default Apache settings on these systems do not let requests make network connections, meaning that the driver will get "Permission denied" errors when it tries to connect to the database. If you run into this, try running:
$ /usr/sbin/setsebool -P httpd_can_network_connect 1
Third-Party Installation Instructions
A number of people have created excellent tutorials on installing the PHP driver.
-
This article by Justin Hileman details the process of installing PHP and additional extensions with Homebrew on macOS. This complements the earlier instructions on this page for installing the driver with Homebrew.
-
» PHP 5.3.1 with Xdebug, MongoDB and Lithium on Ubuntu 9.10 / Apache 2.2
This screencast by Jon Adams demonstrates how to quickly get up and running with PHP 5.3.1, Xdebug, and MongoDB on Ubuntu 9.10 with Apache.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-mongo.installation.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.