Git Product home page Git Product logo

Comments (35)

Rents avatar Rents commented on August 22, 2024 9

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

from laravel-mongodb.

 avatar commented on August 22, 2024 4

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()}'"; ?>

from laravel-mongodb.

r115 avatar r115 commented on August 22, 2024 3

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.

from laravel-mongodb.

brunocascio avatar brunocascio commented on August 22, 2024 2

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

from laravel-mongodb.

Werter12 avatar Werter12 commented on August 22, 2024 1

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.

from laravel-mongodb.

jenssegers avatar jenssegers commented on August 22, 2024

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

from laravel-mongodb.

martinAnsty avatar martinAnsty commented on August 22, 2024

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

from laravel-mongodb.

 avatar commented on August 22, 2024

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?

from laravel-mongodb.

brunocascio avatar brunocascio commented on August 22, 2024

Same problem @cloud-ops

from laravel-mongodb.

jenssegers avatar jenssegers commented on August 22, 2024

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.

from laravel-mongodb.

nadavkav avatar nadavkav commented on August 22, 2024

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

from laravel-mongodb.

jenssegers avatar jenssegers commented on August 22, 2024

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.

from laravel-mongodb.

ryasmi avatar ryasmi commented on August 22, 2024

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

from laravel-mongodb.

alexmon avatar alexmon commented on August 22, 2024

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

from laravel-mongodb.

dweinerATL avatar dweinerATL commented on August 22, 2024

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

from laravel-mongodb.

jonathanpmartins avatar jonathanpmartins commented on August 22, 2024

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()"

from laravel-mongodb.

osadan avatar osadan commented on August 22, 2024

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 .

from laravel-mongodb.

biswajitpanday avatar biswajitpanday commented on August 22, 2024

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

from laravel-mongodb.

a-ghasemi avatar a-ghasemi commented on August 22, 2024

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.

from laravel-mongodb.

jenssegers avatar jenssegers commented on August 22, 2024

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

from laravel-mongodb.

a-ghasemi avatar a-ghasemi commented on August 22, 2024

Thanks for your afforts
On Sat, 30 Jan 2016 at 14:08, Jens Segers [email protected] 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)
.

from laravel-mongodb.

mvladk avatar mvladk commented on August 22, 2024

is there expected release date for support mongodb 3.2?

from laravel-mongodb.

jensk avatar jensk commented on August 22, 2024

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

from laravel-mongodb.

bgarrison25 avatar bgarrison25 commented on August 22, 2024

@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?

from laravel-mongodb.

bgarrison25 avatar bgarrison25 commented on August 22, 2024

@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.

from laravel-mongodb.

jonathanpmartins avatar jonathanpmartins commented on August 22, 2024

@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)

from laravel-mongodb.

jensk avatar jensk commented on August 22, 2024

@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. ;-)

from laravel-mongodb.

mvladk avatar mvladk commented on August 22, 2024

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

from laravel-mongodb.

gsolak avatar gsolak commented on August 22, 2024

@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

from laravel-mongodb.

midium avatar midium commented on August 22, 2024

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

from laravel-mongodb.

nigeltiany avatar nigeltiany commented on August 22, 2024

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

from laravel-mongodb.

lewiswebber avatar lewiswebber commented on August 22, 2024

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.

from laravel-mongodb.

junibrosas avatar junibrosas commented on August 22, 2024

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

from laravel-mongodb.

mohammad-69 avatar mohammad-69 commented on August 22, 2024

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.

from laravel-mongodb.

gvsagar411 avatar gvsagar411 commented on August 22, 2024

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

from laravel-mongodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.