Manual
在线手册:中文 英文
PHP手册

安装

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.1, 5.2, and 5.3.

» PECL 扩展未与 PHP 捆绑。 This page gives more specific information on installing on different systems and troubleshooting issues users have run into.

Installing on *NIX

Run:


$ sudo pecl install mongo

If you are using CentOS or Redhat, Csoke Arpad created » RPMs for these distributions.

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 32MB.

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
$ sudo make install

Make the following changes to php.ini:

OS X

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).

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

If you are using MAMP (or XAMPP and the above command does not work), precompiled binaries are available from » Github (download the latest one with "osx" in the name that matches your version of PHP). Extract mongo.so from the archive and add it to MAMP or XAMPP's extension directory. Add


      extension=mongo.so

to the php.ini file being used and restart the server.

Gentoo

Gentoo has a package for the PHP driver called dev-php5/mongo, which can be installed with:


$ sudo emerge -va dev-php5/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 && 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.)

Installing on Windows

Precompiled binaries for each release are available from » Github 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).

The latest (non-release) code is compiled into Windows binaries on every commit. The zip consists of a .zip with php_mongo.dll and a version.txt. Please keep the version.txt around so that if you have a question or problem, you can give the developers the exact version you're using. (The number is long and nonsensical, but it will make sense to the developers!)

To get the latest bug fixes (and possibly bugs), download the binary corresponding to the PHP you have installed:

Add the following line to your php.ini file:


extension=php_mongo.dll

Third-Party Installation Instructions

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


Manual
在线手册:中文 英文
PHP手册
PHP手册 - N: 安装

用户评论:

soni.harriz (21-Mar-2012 04:17)

i found that php.ini file located in /etc/php.ini , when i open the file, it is empty. i have added the "extension=mongo.so" in the file, but still it didn't work. Can you tell me how to resolve it? every answer is fully appreciated. thanks before

enzo at smshome dot net (10-Aug-2011 04:49)

There is no php_mongo.dll for x64 PHP. PHP doesn't load pre-compiled version (error: "%1 is not a valid Win32 application")

tiago dot braga at gmail dot com (08-Aug-2011 05:04)

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 (27-Jun-2011 09:25)

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.zip\mongo-1.1.4-php5.3vc6ts\php_mongo.dll) to get it working.

Andrey (02-Jun-2011 12:54)

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 (26-Oct-2010 04:26)

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.

Anonymous (13-Mar-2010 06:41)

I was only able to solve an xmapp install problem by accessing the cached version of this page - which was at the time hosted at mongo.

in the comments someone said

Setup on XAMPP
Install the Developer package for XAMPP
Make sure the the Apple Developer Tools are installed
!!!Edit your php.ini file with extension=mongo. For some reason, the build did not work until I did that.
if XAMPP install in your Application folder, run sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo
Restart XAMPP

which worked.

using the github packages it ended up being compiled with different versions of whatever and then threw an error in the log and wasnt included.

cap at unagon dot com (26-Feb-2010 09:52)

For Debian users: apt-get install php5-dev will install phpize for you.