tthlaszlo
tthlaszlo

Reputation: 485

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

I want to use the MongoDB Driver, but it throw me an error, when i use it:

$mongo = new MongoDB\Driver\Manager("mongodb://localhost:27017");

The error:

Message: Class 'MongoDB\Driver\Manager' not found

When i check it with the php_info(), i see, there is enter image description here

Is there any requirement to use the driver?

Upvotes: 27

Views: 131082

Answers (8)

linh dinhvan
linh dinhvan

Reputation: 61

With the new version of centos, editing php.ini does not work anymore,

You need to add the mongodb.ini file with the content extension=mongodb.so in the etc/php.d folder

Then don't forget to restart php-fpm: sudo systemctl restart php-fpm.service

Upvotes: 2

Habib Mammadov
Habib Mammadov

Reputation: 321

How to install on macOS Mojave

Start with:

sudo pecl install mongodb

To check if mongodb package is installed, look for "mongodb" when you run:

pecl list

To get your installed mongodb.so path, run:

pecl list-files mongodb | grep mongodb.so

then remove (or comment out) on your php.ini file:

extension="mongodb.so"

(I could not found a line with extension="php_mongodb.so")

now insert a line with:

extension="{{the path to your installed mongodb.so}}"

Run this command to get your ext-*.ini directory path:

php -i | grep Scan

Create your ext-mongodb.ini with:

touch {{your conf.d path}}/ext-mongodb.ini

like:

touch /usr/local/etc/php/7.1/conf.d/ext-mongodb.ini

Restart your apache to read the new configuration

Sanity check with:

php -i | grep mongodb

You're ready to go.

Upvotes: 8

user12849484
user12849484

Reputation:

This error is because of php_mongodb.dll file is missing in the etc folder and add to the php.ini file like(extension=php_mongodb.dll) . Because of this I got this error. It will rectify my error

Upvotes: 1

Kistlak Rajapaksha
Kistlak Rajapaksha

Reputation: 134

If you get this error, even after you installed the Mongodb driver for php, just install mongodb using composer.

composer require mongodb/mongodb

After that this will solve your problem.

Upvotes: 4

Shashank
Shashank

Reputation: 1

Might be your CLI version of php is different ,check php version in terminal using php -v. and then switch accordingly... FOR EX-:

From PHP 7.1 => PHP 5.6

$ sudo update-alternatives --set php /usr/bin/php5.6.

I hope it will help you guys.

Upvotes: 0

abhishek kumar
abhishek kumar

Reputation: 466

1.Add mongo DB

$sudo apt update && sudo apt install php-mongodb
  1. Restart apache server,

  2. check in phpinfo() for mongo

Upvotes: 11

Ryan DuVal
Ryan DuVal

Reputation: 3934

For me, I forgot to add extension=mongodb.so to the php.ini for FPM (FastCGI Process Manager). On Ubuntu 16.04 this was at:

/etc/php/7.0/fpm/php.ini

For what it's worth I'm using nginx.

Upvotes: 20

simon
simon

Reputation: 2946

There is some confusion between the Mongo extension and the MongoDB extension which are not the same. Because of your version number, I guess you are using the old Mongo extension that is deprecated.

Make sure that you install the new MongoDB extension and you should be fine. Don't forget to remove the old extension=mongo.so from your php.ini since this could cause problems.

Upvotes: 33

Related Questions