Class 'MongoDB\Driver\Manager' not found

Viewed 47867

I'm integrating MongoDB with Laravel. I'm following information found in this link jenssegers/laravel-mongodb. I'm successful at integrating MongoDB. But when I run the code it throws this error

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

Here is the code

Controller app/Http/Controller/NewController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\User;

class NewController extends Controller
{
    //
    public function index(){
        $var = User::all();
        var_dump($var);
    }
}

And here follows the user.php that is by default provided by Laravel when we create the project

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User  extends Eloquent 
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $collection = 'users_collection';
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

Please tell me why am I getting this error.

Phpinfo --> mongodb section is coming. Here is a screen shot phpinfo

8 Answers

You may also need to restart fpm on ubuntu/debian

sudo service php7.0-fpm restart

for php5

sudo service php5-fpm restart

Also, make sure extension=mongodb.so is in:

apache2/php.ini
cli/php.ini
fpm/php.ini

to check i do:

locate php.ini | xargs grep mongo

to see php.ini files:

php --ini

When you are going to connect MongoDB database with any PHP application then you can face this issue if you don't have PHP MongoDB driver.

So first you need to run following command to install Mongodb PHP extension :

sudo apt-get install php-mongodb

Now restart the server :

  sudo service apache2 restart

reference from hdtuto

WINDOWS USERS: In the folder

C:\xampp\php\ext

Copy the php_mongodb.dll file. You can get this file from the link according to your php version, ts or non ts and architecture from this link: https://pecl.php.net/package/mongodb/1.9.0/windows

In windows , if anybody couldn't locate the php.ini file, its in the folder

C:\xampp\php

inside this the php file with the type configuration settings.

I couldnt locate this, as the extension .ini was not showing in mine.

Related