Installing PHP driver for mongoDB

Hmm .. I am not here to give must lecture about mongoDB as I am also a beginner for mongo. Still all I am here to say the interest part of my mogoDB Driver(for PHP) installation on my Linux machine. Don’t worry I am not going to give the installation procedures but going to discuss the mistakes that I was doing.

On my machine I have installed the mongoDB. From command line I will be able to access mongoDB like any other DBMS. PHP is already available in my machine.

Few weeks before I was trying to access monoDB from a PHP page. In order to do this you need PHP driver support for mongoDB. Of course mongo guys provide PHP driver(PECL). I have installed, added the extension to php.ini files and restarted my Apache server. But mongo information were not found on php_info() results. Now headache started. Everything when right but it is not Woking 🙁


nothing worked out. Everything when right still it is not Woking 🙁

Frustrated but did not gave up , I decided to try mongo with java. But for that you once again require java drive support for mongo. This drive is available. I have installed and tried few db transactions . Good it work fine.

‘What the hack is that ..? when it work for java why don’t it work for php’ — questions promoted over my head.

Then I have started mailing the mongo guys and also posted the issue on few forums. mongo guys gave the quick reply they asked for my php_info() results. I replied with what they asked. Within next few mail they pointed out that I have two copy of PHP installed on my machine. I.e. PHP on Apache and another PHP for command line.

Its a simple and idiotic mistake. I was installing driver for PHP that is going to work on my command line and not on the PHP on my Apache. Cool…now what to do to make mogo work with php on my Apache. Follow these steps

  1. Copy to /usr/local/Apache2/php/lib/php/extensions/no-debug-non-zts-20090626
  2. Create /usr/local/Apache2/php/php.ini with one line:
  3. Restart Apache.

It works now

mongo information on php_info()

mongo information on php_info()

Note : You will not get this issue on window because there are less chance of having two copies of php. As most win developer go for WAMP.

Post a Comment

Your email is never published nor shared. Required fields are marked *