1
votes

I get the following error when trying to run a PHP script that access local MongoDB:

Fatal error: Class 'MongoDB\Driver\Manager' not found".

I have setup apache (2.4.23), along with PHP (5.6.25) and MongoDB (2.4.14) and a MongoDB driver (1.1.0). Everything seems to be working from the command line (cli), but when I try to access the DB via the web I get an error saying "

Fatal error: Class 'MongoDB\Driver\Manager' not found".

I am aware that php.ini has a special configuration file for apache (/etc/php5/apache2/php.ini), and I have enabled the mongodb.so extension there. However, I am still getting that error. I double checked that php is actually reading the configuration from there:

Configuration File (php.ini) Path /etc/php5/apache2 Loaded

Configuration File /etc/php5/apache2/php.ini Loaded

According to the MongoDB website ( https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#reference-compatibility-mongodb-php), MongoDB (2.4) is compatible with mongoDB php Driver version 1.1. Again, from the command line, my test script works:

<?php
echo phpinfo();
    
$manager = new MongoDB\Driver\Manager("mongodb://localhost:28124");

Any Ideas?!?!?!?

1
Try new \MongoDB\Driver\Manager(...) (note the leading backslash). This probably won't change anything but it's worth a shot - Phil
Also, did you restart Apache? - Phil
\ or not \ doesn't make a difference. - Shay Ohayon
Apache restart doesn't help - Shay Ohayon
Can this be related somehow to my php installation? I wasn't able to compile it with the apxs flag - Shay Ohayon

1 Answers

1
votes

Problem solved. The issue was that I didn't compile php with apxs support. Once I added that (./configure --with-apxs2=/usr/bin/apxs2) everything was working properly.