PHP 5.4.33 Released


The MongoDB PHP driver should work on nearly any system: Windows, Mac OS X, Unix, and Linux; little- and big-endian machines; 32- and 64-bit machines; PHP 5.2, 5.3, 5.4 and 5.5.

Această extensie » PECL nu este încorporată în PHP.

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 mongodb-mongodb-php-driver-<commit_id>.tar.gz
$ cd mongodb-mongodb-php-driver-<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 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/'
    Make sure that it is the same as the PHP extension directory by runnning:
    $ php -i | grep extension_dir
      extension_dir => /usr/lib/php/extensions/no-debug-non-zts-20060613 =>
    If it's not, change the extension_dir in php.ini or move

  • To load the extension on PHP startup, add a line:

Installing on *NIX


$ sudo pecl install mongo

If you are using CentOS or Redhat, you may wish to install from an » RPM.

Add the following line to your php.ini file:

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 » S3 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:


Notă: Additional DLL dependencies for Windows Users

Pentru ca această extensie să funcționeze, anumite fișiere DLL trebuie să fie accesibile în calea de sistem a Windows din variabila PATH. Pentru informații despre cum poate fi realizat acest lucru, accesați FAQ întitulat " Cum să adaug directorul meu PHP la variabila PATH din Windows" pentru informații despre cum să realizați aceasta. Cu toate că copierea fișierelor DLL din directorul PHP în directorul de sistem al Windows de asemenea funcționează (deoarece directorul de sistem este în mod implicit inclus în variabila PATH), acest lucru nu este recomandabil. Această extensie necesită ca următoarele fișiere să existe în calea PATH : libsasl.dll


If your system is unable to find autoconf, you'll need to install Xcode (available on your installation DVD or as a free download from the Apple website).

In most cases installing from pecl is the easiest way:

$ sudo pecl install mongo

If you are using XAMPP, you may be able to compile the driver with the following command:

$ sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo


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
Then restart Apache. (This issue has also occurred with SELinux.)

Third-Party Installation Instructions

A number of people have created excellent tutorials on installing the PHP driver.

add a note add a note

User Contributed Notes 8 notes

3 years ago
On windows installation check for VC compilator version inside phpinfo(), if you install incorrect one it wouldn't work.
I tried to run on Apache2 with VC6, and always get folowing error:

Fatal error: Class 'Mongo' not found

Until I look into phpinfo and found MSVC9, after that
I install VC9 dll files and it solve the problem.
poorpuer at gmail dot com
3 years ago
If you're running IIS under Windows 7 and have PHP manager installed you'll also need to manually enable the extension. Start IIS Manager, select PHP Manager, under the section labeled PHP Extensions click on Enable or disable an extension, then enable the php_mongo.dll extension, and restart IIS.
cap at unagon dot com
4 years ago
For Debian users: apt-get install php5-dev will install phpize for you.
1 year ago
To install the Mongo driver on Windows 7 x64 with EasyPHP, you have to use the x86 driver (instead of x64) and non nts :
php_mongo-1.3.2RC1-5.4-vc9.dll actually
10 months ago
This may help also:

Xcode doesn't ship with "Command Line Tools", you need to install then after installing Xcode.

You need Command Line Tools to get the program `m4` that you need to install mongo driver using: sudo pecl install mongo.

bradley dot henke at colorado dot edu
1 year ago
Instructions for Manually Installing MongoDB for PHP for use with "XAMPP for Linux":

There were two gotchas that I ran into. "XAMPP for Linux" needs 32 bit libraries, and the php API version must match the php API version of "XAMPP for Linux".
Hopefully this will save someone else time figuring this all out!

1) Install "XAMPP for Linux" AND the "XAMPP for Linux Development Files".

2) Grab the source code from github (in the manual instructions above)
$ tar zxvf mongodb-mongodb-php-driver-<commit_id>.tar.gz
$ cd mongodb-mongodb-php-driver-<commit_id>

There are now some smalls deviation from the manual instructions...
3) PHPize
$ sudo /opt/lampp/bin/phpize

4) Configure
$ ./configure

5) Make changes to the Makefile (XAMPP requires a 32-bit compilation)
- Choose your favorite text editor and open "Makefile"
- Make the following changes:
Line 20: prefix = /opt/lampp
Line 23: prefix = /opt/lampp
Line 25: phpincludedir = /opt/lampp/include/php
Line 27: CFLAGS = -g -O2 -m32
Line 34: EXTENSION_DIR = /opt/lampp/lib/php/extensions/no-debug-non-zts-20100525/
Line 35: PHP_EXECUTABLE = /opt/lampp/bin/php

Make sure you replace </path/to/mongo-php-driver-master>
Line 38: INCLUDES = -I/opt/lampp/include/php -I/opt/lampp/include/php/main -I/opt/lampp/include/php/TSRM -I/opt/lampp/include/php/Zend -I/opt/lampp/include/php/ext -I/opt/lampp/include/php/ext/date/lib -I</path/to/mongo-php-driver-master>/util -I</path/to/mongo-php-driver-master>/exceptions -I</path/to/mongo-php-driver-master>/gridfs -I</path/to/mongo-php-driver-master>/types -I</path/to/mongo-php-driver-master>/mcon

6) Compile
$ sudo make all

7) Copy the static object into the extension directory
$ sudo cp modules/ /opt/lampp/lib/php/extensions/no-debug-non-zts-20100525/

9) Update your php.ini file
- Grab you favorite text editor and open /opt/lampp/etc/php.ini (you'll probably need to use sudo).
- Add the line:

10) Restart "XAMPP for Linux". You should now be able to see Mongo listed in your phpinfo() page! Installation Complete!!!

Good Luck!
tiago dot braga at gmail dot com
3 years ago
In Windows running IIS the directory to instal is "C:\Program Files\PHP\ext". Than you have to install the apropriate MongoDriver version (in my case was mongo-1.1.4-php5.3vc9) and than Restart IIS.

The MongoDB Driver will be available.
rishi at plavaga dot in
3 years ago
I am using XAMPP 1.7.4 (32 bit) on Windows 7. Though it was mentioned that Apache uses a non-threadsafe version of DLL, when used, it was giving me the below error:

PHP Warning:  PHP Startup: Unable to load dynamic library
Warning:  PHP Startup: Unable to load dynamic library 'D:\xampp\php\ext\php_mongo.dll' - The specified module could not be found.

I had to use the thread-safe version (\mongo-1.1.4-php5.3vc6ts\php_mongo.dll) to get it working.
To Top