Search code examples
phpmongodblaravelphp-mongodb

Class 'MongoDB\Driver\Manager' not found Even if php-mongo has been installed


Since I was using MongoDB as the app's database, I have installed MongoDB and jessenger/laravel-mongodb by composer to the app.

After setting up, I get the error

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

But I'm sure it have installed all the requirements.

Mongo has been installed.
$ mongo --version
MongoDB shell version v3.4.0
PHP Mongo driver has been installed as well
$ brew install php55-mongodb
Warning: homebrew/php/php55-mongodb-1.2.5 already installed

See what the ini file is loaded, appears that ext-mongo exists in /usr/local/etc/php/5.5/conf.d/ folder.

$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/5.5
Loaded Configuration File:         /usr/local/etc/php/5.5/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.5/conf.d
Additional .ini files parsed:      /usr/local/etc/php/5.5/conf.d/ext-mcrypt.ini,
/usr/local/etc/php/5.5/conf.d/ext-mongo.ini,
/usr/local/etc/php/5.5/conf.d/ext-mongodb.ini

And finally, phpinfo() doesn't find any words about mongo (Not be loaded?)

Questions are:

  1. Should I add extension= to the php.ini file? If so, what is the correct extension name for OS X? (and how to find them?)

    (I've tried to do that with whatever extension=mongo.so, mongo.dll or mongodb.so and other possibilities. Does not work.)

  2. phpinfo() doesn't show any about mongo, that means PHP mongo drivers were not installed correctly? How to deal with that? Add extension= to the file?

  3. Did I lost something unconcernedly?

I spent much time. Any answers would save my time. Thank you so much.


Solution

  • I didn't solve the problem eventually. But I removed built-in apache2 and PHP then reinstalled them by brew instead. This time I chose apache24 and php70, also turned to php70-mongodb rather than 5.5's.

    By the way, I'm sure that is the problem caused by the package not being installed correctly or setting wrong. But I didn't solve problem toward that way. I chose another (install other versions) instead.

    1. Remove built-in apache

    Let apache stop
    sudo apachectl stop
    
    Remove built-in apache
    sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
    

    2. Install packages by Homebrew

    Install apache (apache is called httpd)
    brew install httpd24
    
    Install php 7
    brew install php70 --with-apache
    
    Install PHP driver of MongoDB
    brew install php70-mongodb --with-apache
    

    3. Restart apache

    sudo apachectl restart