Error 'Class' MongoDB \ Driver \ Manager' not found "

2

At the time of using MongoDB , together with Laravel it returns the following error:

  

FatalErrorException in Client.php line 61:   Class 'MongoDB \ Driver \ Manager' not found

    
asked by anonymous 05.10.2016 / 16:53

2 answers

2

Currently, there are two drivers for MongoDB: mongo and the mongodb .

mongo is bequeathed. mongodb is more current, works with newer versions of PHP, and works with HHVM and more. In the rewrite of the new driver, among other changes, all classes were reformulated and the namespaces changed.

Based on your error of Class 'MongoDB\Driver\Manager' not found it is possible to infer that the library for MongoDB that you are trying to use in conjunction with Laravel, use the newer version of the driver, the mongodb .

The newer version can be installed with pecl . After this installation, this error should stop occurring.

    
11.11.2016 / 14:12
1

It's not a problem in Laravel, it's missing the mongodb module in PHP.

  

Note that there are two versions of the module link

To install the mongodb module you will need:

  • php 5.4 or HHVM 3.9
  • libbson and libmongoc ( link )

Install by PECL:

sudo pecl install mongodb

And then add in php.ini this:

extension=mongodb.so

If it is Windows, download the Thread Safe version at link

Extract php_mongodb.dll and copy it to extensions/ folder and then add it to php.ini:

extension=php_mongodb.dll

Downloading Mongodb from Github

You can try the manual installation via Git, however you will need to compile, however you must install phpize first, if it is Debian or Ubuntu (or based on them) use the command for PHP5:

sudo apt-get install php5-dev

If it is php7.0, 7.1, 7.2 (and futures) use:

sudo apt-get install php7.0-dev

Or:

sudo apt-get install php7.1-dev

Or:

sudo apt-get install php7.2-dev

Then after installing (and having installed Git) run the commands:

git clone https://github.com/mongodb/mongo-php-driver.git
cd mongo-php-driver
git submodule sync && git submodule update --init
phpize
./configure
make all -j 5
sudo make install

You can compile on Windows using Visual Studio too, but you must download link php-devel, for example:

php-devel-pack-5.6.37-nts-Win32-VC11-x64.zip
php-devel-pack-5.6.37-nts-Win32-VC11-x86.zip
php-devel-pack-5.6.37-Win32-VC11-x64.zip
php-devel-pack-5.6.37-Win32-VC11-x86.zip
php-devel-pack-7.0.31-nts-Win32-VC14-x64.zip
php-devel-pack-7.0.31-nts-Win32-VC14-x86.zip
php-devel-pack-7.0.31-Win32-VC14-x64.zip
php-devel-pack-7.0.31-Win32-VC14-x86.zip
php-devel-pack-7.1.21-nts-Win32-VC14-x64.zip
php-devel-pack-7.1.21-nts-Win32-VC14-x86.zip
php-devel-pack-7.1.21-Win32-VC14-x64.zip
php-devel-pack-7.1.21-Win32-VC14-x86.zip
php-devel-pack-7.2.9-nts-Win32-VC15-x64.zip
php-devel-pack-7.2.9-nts-Win32-VC15-x86.zip
php-devel-pack-7.2.9-Win32-VC15-x64.zip
php-devel-pack-7.2.9-Win32-VC15-x86.zip

Choose depending on the version of your VisualStudio and your PHP.

Installing Mongodb on HHVM

If you are using HHVM then you have to download via Git:

git clone https://github.com/mongodb/mongo-hhvm-driver.git
cd mongo-hhvm-driver
git submodule sync && git submodule update --init --recursive
hphpize
cmake .
make configlib
make -j 5
sudo make install

After any of the above processes you may have to restart Apache (or HHVM)

Documentation: link

    
11.11.2016 / 14:29