PECLYou can download and install the driver using PECL by running: $ pecl install mongo Add the following line to php.ini: extension=mongo.so That's it, you're done! Windows InstallThe precompiled driver is available for the following setups: VC8 and VC9Builds for each release are available on Github. They are all build for PHP 5.3, as PHP 5.2 is no longer supported with VC9. Binaries for the latest code are also available: VC6The latest binaries for 5.2 and 5.3 are available at php.net. Please inquire on the mailing list if you need a different build. Install
Manual *NIX InstallGo 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:
System OdditiesOS XIf your system is unable to find autoconf, you'll need to install Xcode (available on your installation DVD).
MAMP and XAMPPMAMP and XAMPP cannot compile the driver, as they are missing some PHP header files. You can download a precompiled .so of the PHP 5.3 thread safe build from Github. MAMP Install Put mongo.so in MAMP's PHP extension directory and add a line to the php.ini used by MAMP that says: extension=mongo.so XAMPP Install
You should be all set to use Mongo from XAMPP! GentooOn Gentoo using PECL you might 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 (Thanks to @riklaunim) Optional ConfigurationThere are also a number of options that can be configured by adding lines to php.ini: [mongo] ; If the driver should reconnect to mongo mongo.auto_reconnect = true ; Whether to allow persistent connections mongo.allow_persistent = On ; Maximum number of persistent connections (-1 means unlimited) mongo.max_persistent = -1 ; Maximum number of links (persistent and non-persistent, -1 means unlimited) mongo.max_connections = -1 ; Default host for mongo connection mongo.default_host = www.example.com ; Default port for mongo database mongo.default_port = 42 ; When saving files to the database, size of chunks to split them into mongo.chunk_size = 1024 ; Specify an alternate character to $ to use for special db functions ($set, $push, $exists, etc.) mongo.cmd = "$" If you do not add any of the above lines, the defaults are: mongo.auto_reconnect = Off mongo.allow_persistent = On mongo.max_persistent = -1 mongo.max_connections = -1 mongo.default_host = localhost mongo.default_port = 27017 mongo.chunk_size = 262400 There are some utility PHP scripts at Github . These can be added to your include path if you would like to use them. They include:
Checking Your InstallationTo check that the extension is working, restart Apache and create a PHP page containing: <?php phpinfo(); ?> Visit the page, scroll down, and you should see a "mongo" section that looks similar to: Your driver should now be fully armed and operational! See the PHP Tutorial to start using it. |


Comments (9)
IF YOU HAVE A QUESTION, POST IT TO THE USER GROUP.
These pages are fine for comments, but for questions, your best bet will always be the MongoDB User Group.Oct 20
Anonymous says:
When using later versions of Fedora (I am using 11), changes need not be made di...When using later versions of Fedora (I am using 11), changes need not be made directly to php.ini. Instead,
Change to root.
Within the /etc/php.d/ directory, create a subdirectory named mongo (or something else you like).
In the mongo directory, create a mongo.ini file.
In the mongo.ini file, write the following code:
Nov 23
Anonymous says:
i have to use an old version of xampp, due to the php version i need. anyway i c...i have to use an old version of xampp, due to the php version i need. anyway i could get a no-debug-non-zts-20060613 version of the mongo.so?
Nov 24
Kristina Chodorow says:
In that case, the .so under the MAMP heading will work fine for you.In that case, the .so under the MAMP heading will work fine for you.
Dec 06
Anonymous says:
I am a junior university student from China. In our database course, our teacher...I am a junior university student from China. In our database course, our teacher asked us to use the MongoDB. I want to use the PHP. However, I cannot install the driver in my windows vista computer. Should I just finish the part in "Windows install" on this page? Or should I first do the "PECL", then "Windows install"?
Dec 06
Kristina Chodorow says:
For Windows, just download the pre-compiled driver. Ignore the section on PECL.For Windows, just download the pre-compiled driver. Ignore the section on PECL.
Dec 07
Anonymous says:
Thanks a lot. I've fixed it. New problem occurred. I don't know why it...Thanks a lot. I've fixed it. New problem occurred. I don't know why it says "fatal error...MongoGridFSException..." when i try to upload a mp3/avi file using the sample code in "File Upload Tutorial". It works very well with jpg/doc file etc.
Jan 05
Anonymous says:
I had a few errors on my system that may help someone else. On one of my boxes I...I had a few errors on my system that may help someone else. On one of my boxes I had a custom install of php (two versions) which would cause the wrong one to get installed. I would get the error...
Module compiled with module API=20060613, debug=0, thread-safety=0
PHP compiled with module API=20050922, debug=0, thread-safety=0
To fix it I had to use the right version of pecl so instead of
$pecl
I had to locate the different version of pecl and use
$/usr/bin/pecl install mongo
Also pecl ran into an out of memory error. To fix this I had to
vi /usr/share/pear/pearcmd.php
and add to the top...
ini_set('memory_limit', '32M');
/http://www.morguefile.com
Feb 05
Anonymous says:
Setup on XAMPP Install the Developer package for XAMPP Make sure the the Apple D...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
Feb 05
Anonymous says:
Debian Install apt-get install php5-dev, php5-pear pecl install mongo Edit php.i...Debian Install
apt-get install php5-dev, php5-pear
pecl install mongo
Edit php.ini files for both apache2 and php-cli
Restart apache server
Add Comment