suhkha's avatar

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

I have my laravel v.53 project with Homestead (before scotchbox). So in Homestead I install mongodb, so if I type:

mongodb --version

I got the version 3.2 so it's ok because I use the package jenssegers/laravel-mongodb First I'm not 100% sure if my config is correct:

database.php

'mongodb' => array(
            'driver'   => 'mongodb',
            'host'     => 'localhost',
            'port'     => 27017,
            'username' => 'mongouser123',
            'password' => 'secret',
            'database' => 'stuff'
        ),

If I do in shell:

mongo -u mongouser123 -p secret 127.0.0.1/stuff

conection is successfully

so.. I have my own model and controller that I use with the package

CustomModel.php

namespace App;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\Model;

class CustomModel extends Eloquent
{
    
    protected $connection = 'mongodb';
    protected $collection = 'things'; //stuff is the database
}

CustomModel.php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Code;

class CustomController extends Controller
{
    public function index(){
        $things = CustomModel::all();
        return View::make('results-mongo',compact('things'));
    }
}

And I have my route so, if I type the route in my browser to display the content of index() I got:

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

What's wrong? Or what's could be wrong? :'( Thank you!!!

0 likes
22 replies
suhkha's avatar

Yes @jimmck, I check that, and the shell return this:

pecl/mongodb is already installed and is the same as the released version 1.2.3
install failed

And in php.ini I put:

extension=mongodb.so
jimmck's avatar

@suhkha From the command line run php -m | grep mongo

Also which php to verify your php.ini matches installed php on path.

suhkha's avatar

@jimmck Hi! I check the path of my php.ini with

php -i

I check the file, and there is the extesion enabled: extension=mongodb.so that what I put the first time.

And if I run:

php -m | grep mongo

the result is: mongodb

So, it seems right to me, but I don't know, nothing change :/

jimmck's avatar

@suhkha The Mongo PHP extension is not loaded. Did you do a which php to see where the default php is located and look at the php.ini

Dump out the Mongo status with php -i.

Also try a simple php mongo command to open your database connection not using anything from Messengers. This will test only that the Extension is installed.

Did you read the Messengers GitHub issues page?

suhkha's avatar

@jimmck I went to the file tha php -i shows, and I can use mongo shell, that's what is weird.. :/

I read a lot and all comments says that I must enable extension, and I did

jimmck's avatar

@suhkha DID YOU RUN which php from the command line.

Show your Work!

jimmck's avatar

@suhkha Where is the mongo information from php -i ?

We are trying to match php.ini files with the which command. Do not open the php exe file in the edit. Open the php.ini in the info screen

jimmck's avatar

Can you run this...

<?php 
use MongoClient;

        $conn = new MongoClient();
        $conn->connect();
suhkha's avatar

Yes, is 1.2.3, in fact I tried update but I get this:

pecl/mongodb is already installed and is the same as the released version 1.2.3 install failed

jimmck's avatar

@suhkha Yup this the problem. This why I have held off 7.1, I have many libraries I have to check and use lots of drivers to hit legacy systems.

Can you find a 1.3 version? I did a quick search but did not find one for 7.x

What are your machine stats? Not your virtual your physical.

If I come across one I will send info. My day of reckoning is sooner since I use MongoClient in my libraries code.

Add it the list!!!

suhkha's avatar

@jimmck I tried, but doesn't let me install, keep saying that I have a current version

sudo pecl install mongodb-1.3.0

pecl/mongodb is already installed and is the same as the released version 1.2.3

:/

suhkha's avatar

Unfortunately I had to use a minor version of laravel (5.2) and the package "jenssegers / laravel-mongodb" (2.3.x)

Thanks a lot for your help!! :)

jimmck's avatar

@suhkha Did you remove the previous version? pecl -help to get options.

meshack007's avatar

If your using valet, restart it after installation.

Bapquad's avatar

If you use 'php -m', it list mongodb. That you have a right mongdb extension version for your PHP. Otherwise, you have a wrong mongoDB extension version. If you have a right mongodb extension, but still meet the error. I think your server software (ex: apache) have a permission problem. You can try with Administrator right for it. Run As Adminstrator with windows or sudo when use *nix.

Please or to participate in this conversation.