PHP Language Center

Using MongoDB in PHP

To access MongoDB from PHP you will need:
  • The MongoDB server running - the server is the "mongod" file, not the "mongo" client (note the "d" at the end)
  • The MongoDB PHP driver installed

Installing the PHP Driver

*NIX

Run:

sudo pecl install mongo

Open your php.ini file and add to it:

extension=mongo.so

It is recommended to add this to the section with the other "extensions", but it will work from anywhere within the php.ini file.

Restart your web server (Apache, nginx, etc.) for the change to take effect.

See the installation docs for configuration information and OS-specific installation instructions.

Windows
  • Download the correct driver for your environment from http://github.com/mongodb/mongo-php-driver/downloads
    • VC6 is for Apache (VC9 is for IIS)
    • Thread safe is for running PHP as an Apache module (typical installation), non-thread safe is for CGI
  • Unzip and add the php_mongo.dll file to your PHP extensions directory (usually the "ext" folder in your PHP installation.)
  • Add to your php.ini:
    extension=php_mongo.dll
  • Restart your web server (Apache, IIS, etc.) for the change to take effect

For more information, see the Windows section of the installation docs.

Using the PHP Driver

To get started, see the Tutorial. Also check out the API Documentation.

See Also


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.

blog comments powered by Disqus