Installing MongoDB driver for PHP on Windows

Mongo extension with MongoClient class is deprecated. Instead, the MongoDB extension should be used.

 

mongoPHP-logo

MongoClient class is included in “Mongo” that is official MongoDB driver for PHP. MongoClient class is required to connect MongoDB and required by several packages that bridge between MongoDB and PHP. Here is detail of this driver on php.net:  http://php.net/manual/en/mongo.manual.php

Mongo works on almost all of Operating Systems including Windows, Mac OS X, Unix, and Linux; little- and big-endian machines. No matter 32 or 64-bit machines. PHP 5.3 through 5.6. To install it, there is a “mongo” package on PECL.

To install Mongo for Windows, you need to do following steps (Tested with Windows 7) :

  1. Download this package from PECL website manually. Go to PECL Mongo package and choose latest stable version’s DLL by clicking on DLL link.
  2. Choose Thread safe x86 version, even for 64 bit system and download it. 64-bit version didn’t work for some people while x86 on 64-bit system worked fine so use download x86 thread safe version.
  3. Extract the zip file that is just downloaded, and place it in your PHP’s ext (extensions) directory. Ext directory can be find through phpinfo().
  4. Once placed in PHP’s ext directory, open your php.ini file and add follwing line and save it:
    extension=php_mongo.dll
  5. Then restart your apache server and test your code which use MongoClient class. It should work now.

In case of any problem, feel free to ask in comments.

10 thoughts on “Installing MongoDB driver for PHP on Windows”

  1. Now I use MongoDB 3.2.0 and it doesn’t support php_mongo.dll instead php_mongodb.dll.
    When I use new MongoClient() or new Mongo(), it’s error. Do you have any suggestion?

  2. we want to configure this with codeigniter we follow each step but still it shoaw some error
    The MongoDB PECL extension has not been installed

  3. i had included php_mongo.dll file in php.ini file, and i am checking whether .dll file is loaded or not , but it tell me “file is not loaded”.(by using extension_loaded(“mongo”) function)
    i had put php_mongo.dll file in php/ext folder….
    and still getting error…

    so,please help me.
    i had tried all version of the .dll file

    1. Once you have placed .dll file and given path in php.ini file, then you need to restart your web server (whether it is apache or nginx) to see any changes.

    2. Also as mentioned above the post, new extension is mongodb not mongo. Please use mongodb extension. And then add

      extension=php_mongodb.dll

      and then restart your server to see if it works.

Share your thoughts