Laravel-mongodb: Class 'MongoDB\Driver\Manager' not found - PROBLEM

Created on 27 Mar 2017  路  18Comments  路  Source: jenssegers/laravel-mongodb

Hello Guys,
I'm using Laravel 5.4 with Valet. I've installed PHP 7.1 and MongoDB drivers for PHP. I've followed every instruction to setup my Laravel project with MongoDB but when I try to communicate with my DB I get this error:

FatalThrowableError in Client.php line 81:
Class 'MongoDB\Driver\Manager' not found

I checked my extensions in my PHP.ini and it's all there. Everything is fine but my project won't work. Can someone help me?
Thanks
schermata 2017-03-27 alle 11 45 03

duplicate question

Most helpful comment

If the mongo driver doesn't show up there try installing it this way:
(Suit this to your php version.)

$ brew tap homebrew/php
$ brew install php56-mongodb

Then add this to your php.ini

extension='/usr/local/opt/php56-mongodb/mongodb.so'

All 18 comments

Do you have the following in your Users model?

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;

class User extends Eloquent implements Authenticatable {
    use AuthenticableTrait;

I missed use Illuminate\Auth\Authenticatable as AuthenticableTrait;
Thank you so much my friend 馃憤
It works now!

I am having the same issue but with a much simpler setup, here is the only class that is using the Jenssegers\Mongodb\Eloquent\Model.

<?php

namespace App\Models;

class Template extends BaseModel
{
     protected $fillable = ['title'];
}

Which inherits from

<?php

namespace App\Models;

use Jenssegers\Mongodb\Eloquent\Model as EloquentModel;

abstract class BaseModel extends EloquentModel
{
    protected $connection = 'mongodb';
}

The migrations and seeds work fine, they write to mongo and everything but when I try and hit one of our routes base_url/templates which should return a list of template models I get the error mentioned above. I have the same setup as well, _php71_, _valet_, _laravel 5.4_. Is there anything else that could cause this error?

Hi @ericadamski, I'm having the same trouble.
Did you figure out what's wrong?

@adrianxplay as long as you installed the php driver for mongo then you should be good. I had to just restart my machine and it seemed fine after that.

@ericadamski I have already installed the php driver, restarted many times and still not working. I guess I'll using php 7.0.
Thanks.

Have you tried creating a php file with

<?php
phpinfo();

See if the Mongo driver shows up there.

If the mongo driver doesn't show up there try installing it this way:
(Suit this to your php version.)

$ brew tap homebrew/php
$ brew install php56-mongodb

Then add this to your php.ini

extension='/usr/local/opt/php56-mongodb/mongodb.so'

I started experiencing this issue in the middle of a project using Homestead, with no obvious config changes to explain the sudden problems. I believe I traced it back to a difference in the required drivers for PHP 7.1 - I think my Homestead box may have updated itself from a version using PHP 7.0 to 7.1, and the apt package php-mongodb wasn't enough anymore. There's some conjecture here, I may be totally off-base, I stopped digging when I solved it.

I ended up resolving this by pasting the code provided by ekandreas at http://forgerecipes.com/recipes/135 into my after.sh provisioning script in the project root.

Try restarting your FPM service after installation. I had the same issues and restarting FPM seems to have solved it.

After I installed php-mongodb, I restart apache, then woked fine for me.

I have installed mongodb 1.3.4 with lumen 5.4 and php 7.1.8.

Ran brew tap homebrew/php -> Ran brew install php71-mongodb

Added extension=/usr/local/opt/php71-mongodb/mongodb.so in php.ini for php 7.1.8.

Also tried cp /usr/local/Cellar/php71-mongodb/1.3.4/mongodb.so /Applications/MAMP/bin/php/php7.1.8/lib/php/extensions/no-debug-non-zts-20160303/ -> Added extension=mongodb.so

Restarted Apache -> Restarted Mongo -> Restarted FPM -> Restarted machine.

But nothing seems to work. I still get the error mentioned in the question. artisan migrate seems to work fine. Also everything works fine on php 7.0.22, but I need php 7.1 for some other packages which are necessary.

I'm using windows 10 and wamp server.

If using PHP 7.0 also installed latest mongodb driver 1.4.1 also, And added in extension=php_mongodb.dll not getting with extension while seeing phpinfo() also.

Restarted Wamp server -> Restarted Machine also its not working at all.

Wamp server having both PHP 5.6 & 7.0 versions. While using PHP 5.6 version its working mongodb.

If you can't see the mongo module in phpinfo it must not be installed properly but that is out of scope of this project @msankar1991

If you are using homestead:
Homestead.yaml
mongodb: true
Then re-provision your Homestead box:
vagrant reload --provision
https://medium.com/@williamvicary/installing-mongodb-on-homestead-3eb750dcc891

This issue really confused me!!
My problem is as same as yours and here is my StackOverflow question, https://stackoverflow.com/q/51078247/3534952.

My Os is Debian8 and a DirectAdmin on it. I do every thing step by step as I know or as I find, but the php not recognize the driver extension!!!

Everything in my local is done, I just want to publish my project!!!
I really need help!

I'm using windows 10 and wamp server.

If using PHP 7.0 also installed latest mongodb driver 1.4.1 also, And added in extension=php_mongodb.dll not getting with extension while seeing phpinfo() also.

Restarted Wamp server -> Restarted Machine also its not working at all.

Wamp server having both PHP 5.6 & 7.0 versions. While using PHP 5.6 version its working mongodb.

what is the resolution ?

I solved this issue by adding
extension= '/usr/local/opt/[email protected]/pecl/20180731/mongodb.so'

in php.ini file. (/usr/local/etc/php/7.3/php.ini)

Was this page helpful?
0 / 5 - 0 ratings