Progi1990
Progi1990

Reputation: 57

Class MongoDB\Driver\Manager' not found

I am using XAMPP. Installed mongo version 3.4.1 If I hit $mongo command I get -

MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.1

And If I hit $php -i | grep mongo then I get -

mongodb support => enabled
mongodb version => 1.2.2
mongodb stability => stable
libmongoc version => 1.5.0
mongodb.debug => no value => no value

I have required "jenssegers/mongodb": "^3.1" in laravel version 5.1

I have configured laravel with mongo in database.php Also migrated using PHP artisan mitrate command and tables have been created in mongo.

After routing, I have added just

DB::collection('collection_name')->get();

But I am getting "FatalThrowableError in Client.php line 81: Class 'MongoDB\Driver\Manager' not found" error

Can anybody help me here? I don't know what is happening! Is there something like I have installed mongo from a command prompt and I am using XAMPP?.

Upvotes: 1

Views: 7566

Answers (2)

Check the default version of php you are using. Try to run phpinfo() in a php page. You can create a php file and include this in the file: <?php phpinfo(); ?> If you do not see Mongodb info on the page loaded then it does not communicate with the current running php version. Check the current php version at the top of the page. The latest php version is php7.1. This is what mongodb uses to run. uninstall the lower version of php using the command: apt-get uninstall php7.0 make sure to include the correct version of php you are removing. install the latest version using the command: apt-get install php7.1, (be sure to install the latest version of php)* as at the time this documentation was being written the current version was php7.1 Be sure to make changes in the vagrant box. Exit the box by typing exit. This logs you out of the box. do a vagrant provision if you get this error: Open the vagrant homestead.rb file on your IDE and do the following: Search for /etc/php/7.0/php-fpm.conf. replace it with /etc/php/7.1/php-fpm.conf Replace all the php7.0 with php7.1. If you are using sublime text IDE, Search for the occurrence of /etc/php/7.0/php-fpm.conf by pressing CTRL+SHIFT+F then type the values to search for. Click the file that has the occurrence and replace the 7.0 with 7.1 Save all the changes made. get back to your git bash. run sh init.sh for the changes to effect. type yes to overwrite the current homestead.yaml. Do a vagrant up to start the box. Vagrant provision to run any configured provisioners on the file

Upvotes: 0

jmikola
jmikola

Reputation: 6922

Compare the output between php -i on the CLI and phpinfo() from a web SAPI. In particular, compare the "Loaded Configuration File" value and paths to various INI files loaded by each SAPI. It is likely that each is using a different php.ini configuration and the extension is only being loaded for the CLI environment.

Upvotes: 1

Related Questions