Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'MongoClient' not found? #36

Closed
Cein-Markey opened this issue Sep 10, 2013 · 35 comments
Closed

Class 'MongoClient' not found? #36

Cein-Markey opened this issue Sep 10, 2013 · 35 comments

Comments

@Cein-Markey
Copy link

Class 'MongoClient' not found in Connection.php on line 132. This is the error received when I try to run migrations - ($ php artisan migrate). Any Ideas? Thanks in advance.

@jenssegers
Copy link
Contributor

Does this only happen when using migrations? Because MongoClient is the native PHP class.

@martinAnsty
Copy link

Looks like an issue with the php-mongo extension not being loaded by PHP. Check phpinfo() and see if the Mongo extension is being loaded, if not check your php.ini file or load the extension through a separate mongo.ini file in conf.d

@ghost
Copy link

ghost commented Oct 23, 2013

What is I get the same error (Class 'MongoClient' not found) but Mongo is enabled within PHP.
I also checked phpinfo() within laravel to make sure it loads it (and not only via cli/configuration files).

Any idea?

@brunocascio
Copy link

Same problem @cloud-ops

@jenssegers
Copy link
Contributor

Can you create an instance of MongoClient without this library? I don't think this error is related to this library, but with your Mongo installation.

@brunocascio
Copy link

Yes! I fixed it.
MongoLid -> https://github.com/Zizaco/mongolid-laravel#troubleshooting

@nadavkav
Copy link

nadavkav commented Jun 7, 2014

Thanks @brunocascio , you last (above) comment was very helpful 😄

@jenssegers
Copy link
Contributor

There is also a new project that is creating a MongoDB driver that you can include using composer: https://github.com/mongofill/mongofill

But I have not tested it yet.

@ryasmi
Copy link

ryasmi commented Jun 23, 2014

Same here @brunocascio, that last comment helped me too, thanks 😸

@alexmon
Copy link

alexmon commented Jul 15, 2014

Same here @brunocascio, your last comment helped me.
As soon as i setup mongo PHP driver message disappears

@dweinerATL
Copy link

@jenssegers I am getting this same error. I have confirmed via a phpinfo() statement that the Mongo driver has loaded

@r115
Copy link

r115 commented Nov 10, 2014

My experience using Ubuntu is that once the PHP MongoDB driver is correctly installed you will have to add the line extension = mongo.so to both the /etc/php5/cli/php.ini and /etc/php/apache2/php.ini.

I had the exact error and that is what solved it for me.

@Rents
Copy link

Rents commented Dec 21, 2014

If your "php -i" shows that Mongo enabled, but you're still getting the same error, that means you need to restart something. Lost a few hours before it downed on me to restart php-fpm.

Solution for php-fpm (Ubuntu):

  1. Create new file in /etc/php5/cli/conf.d/ :
    sudo vi /etc/php5/cli/conf.d/20-mongo.ini
  2. Type "extension=mongo.so" in that file and save file.
  3. After that you need to restart php-fpm service:
    sudo service php5-fpm restart

As you have now have two declaration "extension=mongo.so", it would be better to comment line "extension=mongo.so" in your php.ini

@jonathanpmartins
Copy link

It can be a Mongo integration problem, but if it isn't, and if like me, you are using native MongoDB commands with PHP, try to put a backslashe before the class, like so: "\MongoClient()"

@osadan
Copy link

osadan commented Aug 24, 2015

I had the same problem . after I upgraded my Yosemite to 10.10.5 . all answers above did not solved my problem . my php --ini displayed that the mongo drive is loaded . But still got the error .
and php -v showed that I am running php version 5.6.
What worked for me eventually copying the libexec/apace2/phpLibModule to the apace libexec directory .
It turned out that the apache was running version 5.5 .

@biswajitpanday
Copy link

Thanks man. I am using Linux Mint. To solve this issue i added "extension=mongo.so" (Without quotes) in two directories -

  1. /etc/php5/cli/php.ini
  2. /etc/php5/apache2/php.ini

@a-ghasemi
Copy link

I have same problem on php new release, 7.0.2 . it has no mongoClient anymore and uses mongoDB extension! Now how can I use jenssegers/laravel-mongodb in my new server? please help about this asap.

@jenssegers
Copy link
Contributor

@a-ghasemi There's a separate branch for this. Will be released as a new major version soon.

@a-ghasemi
Copy link

Thanks for your afforts
On Sat, 30 Jan 2016 at 14:08, Jens Segers notifications@github.com wrote:

@a-ghasemi https://github.com/a-ghasemi There's a separate branch for
this. Will be released as a new major version soon.


Reply to this email directly or view it on GitHub
#36 (comment)
.

@mvladk
Copy link

mvladk commented Feb 10, 2016

is there expected release date for support mongodb 3.2?

@jensk
Copy link

jensk commented Feb 10, 2016

@mvladk Version 2.3.x works well with mongodb 3.2.

@bgarrison25
Copy link

@jenssegers I see your 3.0 branch that uses mongodb pecl extension but I can't figure out how to install this with composer. if I put in "3.*" in my composer.json it yells at me because you haven't released it yet. How might I be able to use this or is there a release date for this?

@bgarrison25
Copy link

@jensk it might work well with mongodb 3.2 but php 7 now uses a new pecl extension called "mongodb" instead of "mongo" and this is causing the "MongoClient not found" error. That is what he is talking about.

@jonathanpmartins
Copy link

@bgarrison25 Use the master branch.

"jenssegers/mongodb": "dev-master"

I think the 3.0 version is not finished yet. I use the master branch to do all my test before shipping to php7 server. The "MongoClient not found" is because you are using a old mongo client.

I had a diferente issue, but I guess you can get rid of this message, compiling _libmongoc_ again, and installing the mongo client via pecl. Look up mongodb/mongo-php-driver#219 (comment)

@jensk
Copy link

jensk commented Feb 10, 2016

@bgarrison25 Indeed, php 7 requires a new driver called mongodb. (only supported by the current master branch, no release yet) Though, in my post I just answered the question about mongodb 3.2 support. ;-)

@mvladk
Copy link

mvladk commented Feb 10, 2016

@bgarrison25, exactly. finally it some how worked with "mongodb" and composer
"laravel/framework": "5.1.*",
"jenssegers/mongodb": "~3.0",

@gsolak
Copy link

gsolak commented Feb 22, 2016

@mvladk - thank you. Upgrading composer to ~3.0 jenssegers/mongodb fixed it for me.

Running Windows + php 7.0.1 + mongodb 3.2.1

composer.json
"laravel/framework": "5.2.*",
"jenssegers/mongodb": "^3.0"

php -i | grep
mongodb support => enabled
mongodb version => 1.1.2
mongodb stability => stable
libmongoc version => 1.1.2

The versioning is from:
https://pecl.php.net/package/mongodb

Some tips:

  1. Make sure CLI php and apache php is the same (as mentioned before). Hopefully composer will fail on installation without the proper mongodb extension.
  2. initially I had the .dll named as "mongo.dll" ... I recommend keeping it as "php_mongo.dll".
  3. Make sure php is in Windows' path
  4. http://php.net/manual/en/mongodb.installation.windows.php

@ghost
Copy link

ghost commented Mar 11, 2016

The following php code runs fines on command line, but it failed to open in browser, with error class not found. There's one possible cause is that even the phpinfo() page shows /etc/php-zts.d/mongodb.ini is loaded, but it doesn't show anything else for mongodb module, the mongodb.so file is already defined in the ini file, spent long time can't figure out the reason, pls advise how to proceed?

Fatal error: Class 'MongoDB\Driver\Manager' not found in /var/www/vendor/mongodb/mongodb/src/Client.php on line 56

test.php

demo->beers; $result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] ); echo "Inserted with Object ID '{$result->getInsertedId()}'"; ?>

@midium
Copy link

midium commented Mar 22, 2016

For all having problems with MongoClient function on php7 please check the following link:
http://stackoverflow.com/questions/34486808/installing-the-php-7-mongodb-client-driver

Basically as php7 uses a new driver class for MongoDB they has changed the function to be called.
Hope this can help

@nigeltiany
Copy link

nigeltiany commented Jun 12, 2016

Having the same issue as @goopter. Lets revisit this issue here on github please

@lewiswebber
Copy link

Thanks to @Rents answer I fixed this issue.
If you installed PHP with brew, do brew services restart php70 or php56 if you use version 5.6.x.

@junibrosas
Copy link

I do not know but all the things above did not work for me.

Here is my workaround:

Install MongoDB client
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Install MongoDB driver for PHP
http://www.bictor.com/2015/02/15/installing-mongodb-for-php-in-ubuntu-14-04/

If you come across with configure: error: sasl.h not found! error, use:

sudo apt-get install libsasl2-dev

for CentOS:
yum install cyrus-sasl-devel

@mohammad-69
Copy link

I have the same problem on homestead with php 5.6 - laravel give me the same error but strange thing is I can work with mongo in php artisan tinker and I can migrate but in browser it shows : Class 'MongoDB\Driver\Manager' not found. I'm using "jenssegers/mongodb": "^3.1", in my composer.json file.

@gvsagar411
Copy link

gvsagar411 commented May 29, 2017

i got the error as Fatal error: Class 'Mongoclient' not found in D:\xampp\htdocs\mongo.php on line 3
for fixing this to get mongodb driver i have added this extension=php_mongodb.dll in php.ini file, but still the error was not fixed. can anyone please help me to get out of this issue

@Werter12
Copy link

Werter12 commented Nov 5, 2017

Hi! For those who use vagrant/homestead (also different versions of jenssegers/mongodb for two projects on one homestead)and as I stumbled on this problem, my solution will be useful. So, homestead (6.4.0) use php cli 7.1 as default and command 'php artisan' run by default cli. So if you face 'MongoClient' problem, that means you use not right cli version. In order to use right cli version you have to specify 'php5.6 artisan' or 'php7.1 artisan'. Also you must have right extension in php.ini. mongo.so - for old projects, mongodb.so - for new projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests