OPTIONS

PHP MongoDB Driver

Access MongoDB from PHP

To access MongoDB from PHP you 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.

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

Note

pecl requires that pear be installed. For Debian-based distributions, you may need to run the following:

sudo apt-get install php5-dev php5-cli php-pear

or, for Red Hat-based distributions:

sudo yum install php5-devel php5-cli php-pear

Windows

  • Download the correct driver for your environment from <https://s3.amazonaws.com/drivers.mongodb.org/php/index.html>. Thread safe builds are used when running PHP as an Apache module (typical installation); non-thread safe builds, which include “nts” in the filename, are used for CGI.

  • Unzip and add the appropriate 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.

Compatibility

supported. compatible. anything incompatible will be fixed: Supported
unsupported. minor incompatibilities may exist: Minor incompatibility
unsupported. incompatible: Unsupported

MongoDB Compatibility

        MongoDB Version
    2.4 2.6 3.0
  1.2 Minor incompatibility Minor incompatibility Minor incompatibility
  1.3 Supported Minor incompatibility Minor incompatibility
  1.4 Supported Supported Minor incompatibility
  1.5 Supported Supported Minor incompatibility
  1.6 Supported Supported Supported
Driver Version phongo [1] Supported Supported Supported
[1]Under development: this driver is not yet released.

Older server versions are unsupported.

Language Compatibility

              Language Version
    5.2 5.3 5.4 5.5 5.6 7.0
  1.2 Supported Supported Supported Supported Minor incompatibility Unsupported
  1.3 Minor incompatibility Supported Supported Supported Minor incompatibility Unsupported
  1.4 Minor incompatibility Supported Supported Supported Minor incompatibility Unsupported
  1.5 Minor incompatibility Supported Supported Supported Supported Unsupported
  1.6 Unsupported Supported Supported Supported Supported Unsupported
Driver Version phongo [2] Unsupported Minor incompatibility Supported Supported Supported Unsupported
[2]Under development: this driver is not yet released.

See Also

Documentation

To get started, see the Tutorial and the API Documentation.