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 'MongoDB\Driver\Manager' not found #1358

Closed
lzao opened this issue Nov 7, 2017 · 34 comments
Closed

Class 'MongoDB\Driver\Manager' not found #1358

lzao opened this issue Nov 7, 2017 · 34 comments

Comments

@lzao
Copy link

lzao commented Nov 7, 2017

Hello,
I'm using Php7.1, Laravel 5.5, and Mongo 3.4.10 as Dockers.

In the .../vendor/mongodb/mongodb/src/Client.php file, the corresponding FatalThrowableError Class 'MongoDB\Driver\Manager' not found appears on line 83.

In the Model

<? php

namespace App\Models\Mongo;

use Jenssegers\Mongodb\Eloquent\Model as Moloquent;

class Keywords extends Moloquent
{
     protected $connection = 'mongodb';
     protected $collection = 'keywords';
}

I used the code,

In the Controller,

public function keyword ()
{
     Keywords::all();
}

I used the code.

The database.php file contains

'mongodb' => [
     'driver' => 'mongodb',
     'host' => '127.0.0.1',
     'port' => '27017',
     'database' => 'test',
],

I put this code in it.

I've been looking for the same error since yesterday, but it's still the same.
Help is urgently needed.

@rkgarcia
Copy link

rkgarcia commented Nov 9, 2017

Are you adding the ServiceProvider? Update your mongodb driver

@Juli55
Copy link

Juli55 commented Dec 16, 2017

For me the same problem, but in migration and seeding it works but not in the website

@prog-24
Copy link

prog-24 commented Dec 23, 2017

Duplicate of #1163

@doliskani
Copy link

iI have the same problem, please help me one

@rkgarcia
Copy link

rkgarcia commented Dec 1, 2018

@doliskani do you have the mongodb extension installed and activated?

@doliskani
Copy link

Yes I did.
I use Laravel 5.7 and my php version is 7.2.4 and also mongodb extension is Thread Safe (TS) x64 version 1.5.3

@rkgarcia
Copy link

rkgarcia commented Dec 2, 2018

Please share the output of php -m command share more information about OS i suspect that you use Windows and you need the 32 bits versión of driver

@doliskani
Copy link

C:\wamp64\bin\php>php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
gd
gettext
gmp
hash
iconv
imap
intl
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
Reflection
session
SimpleXML
soap
sockets
SPL
standard
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

[Zend Modules]

I don't understand why it does't display Mongo at here but it is shown in the output of the phpinfo()

a

@rkgarcia
Copy link

rkgarcia commented Dec 2, 2018

Please follow the issues:
#1358
#761
#1163
#1093

@doliskani
Copy link

None of the above links resolved my issue
I installed jenssegers as follows :
composer require jenssegers/mongodb --ignore-platform-reqs
Can it help to solve?

@doliskani
Copy link

doliskani commented Dec 2, 2018

I can store the information using the command line, but I can't in Laravel, where is the problem?
and i added
Jenssegers\Mongodb\MongodbServiceProvider::class,
in service provider

@rkgarcia
Copy link

rkgarcia commented Dec 3, 2018

Please install without the --ignore-platform-reqs, please share the output of command php --ini

@doliskani
Copy link

capture
Thanks

@doliskani
Copy link

I'm really helpless, why this error does not fix

@rkgarcia
Copy link

rkgarcia commented Dec 6, 2018

I'm really helpless, why this error does not fix

You need to update your mongodb extension.

@aanimation
Copy link

aanimation commented Feb 10, 2019

hi all, i was trial and error how to find solutions Class 'MongoDB\Driver\Manager' not found
i just flow the machine (macbook air with mojave), MAMP + php7.1.19, another php installed 7.2.7, but in MAMP i used 7.1.19 as default.

First problem : i cant do composer install/update, since use jenssegers/mongodb,
machine said, i need an extension for mongodb support,
First solved : research how to install this extension to my default php installed.
solved by (http://php.net/manual/en/mongodb.installation.manual.php)
`Manually Installing the MongoDB PHP Driver

$ git clone https://github.com/mongodb/mongo-php-driver.git
$ cd mongo-php-driver
$ git submodule update --init
$ phpize
$ ./configure
$ make all
$ sudo make install`

If you have problem with configure, just do :
$ brew install autoconf

then i check file mongodb.so in php/php7.1.19/lib/php/extensions/no-debug-non-zts-20160303 has already created.

i check php.ini too (php/pph7.1.19/conf), make sure that extension. But I remember I was wrote this line before (another research) : 
extension=mongodb.so in ; Extensions groups.

I just double check.



Second problem,
I check phpinfo in browser, I’m not find word as mongo, I’m little frustate. Huuftt.
Ok, I check php -m in terminal, no mongo found too.

Im going to try run mongod in terminal. Then recheck last action : phpinfo + php -m. Result shown me more frustation.

The research (mac) :
I found in folder php/pph7.1.19/conf there are files :

  • php.ini
  • Php.ini.temp
  • Pear.conf
    What is temp file, when temp file created ? (May someone can explain it). I just check it the contents and look like php.ini contents.

OK..I wrote a line extension for mongo too, like before.
Then restart server (in MAMP) & check phpinfo :
mongodb show detailed. I think I was success then happy,

Back to terminal and check php -m, no mongo again. Huuuft

i research by delete temp file (backup before) then do some last step, but not working, so i restore file and recheck

Final
Wait…I check php —ini result:
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php7.1.19/conf Loaded Configuration File: /Library/Application Support/appsolute/MAMP PRO/conf/php7.1.19.ini
Loaded conf different with conf file.

so…I get this file, to add line extension=mongodb.so, I hope this make sense.

Result
Restart server and re-check like before, hahahahaha… mongo is running.
Phpinfo and php module should be show mongo

NOTE : mongod still running on other tab in terminal. You can check in browser as http://127.0.0.1:27017/

To make sure mongodb already in machine what I expected for my app (Laravel 5.6 + postgre + mongodb for logging).

php artisan migrate:fresh —seed get successfull.

btw..thanks for all, for comments.

Im a amateur for this case, im newbie for Mac, this first half-year using Mac-OS.
I hope some friends can explain in advanced. 👯‍♂️

sorry late, composer update successfull while mongo client was running,
http://127.0.0.1:27017/ shown
It looks like you are trying to access MongoDB over HTTP on the native driver port.

@devenpateldp
Copy link

Laravel Version: 5.7
PHP Version:7.1
Laravel-admin: latest

After first installing
https://github.com/jenssegers/laravel-mongodb

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to a member function prepare() on null

Symfony\Component\Debug\Exception\FatalThrowableError
…/vendor/laravel/framework/src/Illuminate/Database/Connection.php326

vendor/laravel/framework/src/Illuminate/Database/Connection.php

any solution?

@Messhias
Copy link

Messhias commented Nov 4, 2019

I'm facing the same issue and this doesn't have any direct relation with your PHP Mongo DB driver, I'm running the project inside a docker self container environment and the issue still happening (I'm running the composer inside the same Docker context).

I'm using PHP 7.4 with Laravel's latest version.

When I downgraded to PHP 7.1 it worked fine.

I guess the issue there's a relation with PHP version itself than with MongoDB, anyway, this does not only happen when I do composer require it's happening too when I tried to do composer update.

This issue is very common with this library and usually, my solutions are going to the core of the library and change everything by myself and sometimes when I run the composer <require/update/remove> --ignore-platform-reqs works.

The issue in my case is on the file vendor/mongodb/mongodb/src/Client.php line 107 on the constructor function, code bellow:

public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [], array $driverOptions = [])
    {
        $driverOptions += ['typeMap' => self::$defaultTypeMap];

        if (isset($driverOptions['typeMap']) && ! is_array($driverOptions['typeMap'])) {
            throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array');
        }

        $this->uri = (string) $uri;
        $this->typeMap = isset($driverOptions['typeMap']) ? $driverOptions['typeMap'] : null;

        unset($driverOptions['typeMap']);

        $this->manager = new Manager($uri, $uriOptions, $driverOptions);
        $this->readConcern = $this->manager->getReadConcern();
        $this->readPreference = $this->manager->getReadPreference();
        $this->writeConcern = $this->manager->getWriteConcern();
    }

For some reason, the Driver Manager is gone (and I tried to search and the driver is really gonne, why removed?!).

Anyway, for now, the only solution it seems like we have to downgrade to 3.5 and wait for the fix.

@Smolevich
Copy link
Contributor

@Messhias show example for docker-compose configuration and steps for reproducing problem

@Messhias
Copy link

Messhias commented Nov 4, 2019

@Messhias show example for docker-compose configuration and steps for reproducing problem

Do you mean you need the Dockerfile configuration?

@Smolevich
Copy link
Contributor

@Messhias show example for docker-compose configuration and steps for reproducing problem

Do you mean you need the Dockerfile configuration?

Yes and versions for php mongo driver and extension

@Messhias
Copy link

Messhias commented Nov 4, 2019

@Messhias show example for docker-compose configuration and steps for reproducing problem

Do you mean you need the Dockerfile configuration?

Yes and versions for php mongo driver and extension

@Smolevich
All the necessary information you can found out in my dev Dockerfile, unfortunately, I cannot share the production one as per classified issues, but the only difference between the 2 files are the ENV vars which there's no relation with the issue that we're facing right now.

In fact, I strongly suggest use this Dockerfile in future versions of the library but this is the one that I use when the library broken or some unfixed issue happens to debug by myself and change the core.

FROM devilbox/php-fpm-7.4:latest

# opcache configurations.
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="1" \
    PHP_OPCACHE_MAX_ACCELERATED_FILES="33531" \
    PHP_OPCACHE_MEMORY_CONSUMPTION="2048" \
    PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" \
    PHP_OPCACHE_FILE_OVERRIDE=1


# updating the S.O.
RUN apt-get update

# installing the apt-utils package.
RUN apt-get update -y && apt-get install -y --no-install-recommends apt-utils

# installing the pdf libraries.
RUN ln -s /usr/local/bin/wkhtmlto /usr/bin/wkhtmltopdf
RUN apt-get install -y xvfb libfontconfig wkhtmltopdf

# getting the dependencies
RUN apt-get install -y zlib1g-dev \
    libjpeg-dev \
    libpng-dev \
    libfreetype6-dev \
    libreadline-dev \
    libjpeg62-turbo-dev \
    libonig-dev \
    build-essential \
    libzip-dev


# updating the dependencies.
RUN apt-get update -y

# Install Dependencies
RUN ACCEPT_EULA=Y apt-get install -y \
    unixodbc \
    unixodbc-dev \
    libgss3 \
    odbcinst \
    locales \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen

RUN ln -s /usr/lib/x86_64-linux-gnu/libsybdb.a /usr/lib/

RUN apt-get update -y \
	&& apt-get install -y libmcrypt-dev \
	&& rm -rf /var/lib/apt/lists/* \
	&& pecl install mcrypt-1.0.2 \
	&& docker-php-ext-enable mcrypt


# turning on the extensions
RUN docker-php-ext-install gd
RUN docker-php-ext-install opcache

# install mongodb library
RUN apt-get update -y
RUN apt-get -y install gcc make autoconf libc-dev pkg-config libssl-dev
RUN pecl install mongodb
RUN docker-php-ext-install bcmath
RUN echo "extension=mongodb.so" >> /usr/local/etc/php/conf.d/mongodb.ini

# Install Laravel dependencies
RUN docker-php-ext-install iconv mbstring \
    && docker-php-ext-install zip \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install gd

# enable the redis extension.
RUN pecl install -o -f redis \
    &&  rm -rf /tmp/pear \
    &&  docker-php-ext-enable redis

# copying custom php.ini configurations into the container.
COPY docker/php/conf.d/opcache.ini /usr/local/etc/php/conf.d/opcache.ini

# adding the bmacth extension for telescope watcher
RUN docker-php-ext-install bcmath

# creating the working DIR
RUN mkdir -p /code
ENV HOME=/code
WORKDIR $HOME

# setting the default user into the working dir
USER root
COPY ./ $HOME

@Messhias
Copy link

Any updates about this issue?

@Smolevich
Copy link
Contributor

Smolevich commented Nov 10, 2019

@Messhias notify me in here or slack community(Link here) tomorrow

@Messhias
Copy link

@Smolevich let's continue this discussion by slack and let's hope to @jenssegers accept the propose.

@divine
Copy link
Contributor

divine commented Feb 15, 2020

Hello,

This has nothing to do with this library, it's an issue with missing/incorrect settings for mongodb extension.
For more information see: https://jira.mongodb.org/browse/PHPC-656

Thanks.

@divine divine closed this as completed Feb 15, 2020
@Kistlak
Copy link

Kistlak commented Mar 3, 2020

If you get this error, even after you installed the Mongodb driver for php, just install mongodb using composer.

composer require mongodb/mongodb

After that this will solve your problem.

@webmaster-hm
Copy link

I had the same issue. I have solved it changing the permissions on the library mongodb.so, because after the installation the file had 644 and I changed to 755 and it worked.

@cybusnoor
Copy link

I had the same issue and the following two commands solved my issue

sudo apt-get install php-mongodb

sudo service apache2 restart

@AngusDV
Copy link

AngusDV commented Apr 29, 2022

i am have a same issue

php7.3 -m
PHP Warning:  PHP Startup: Unable to load dynamic library 'mongodb.so' (tried: /usr/lib/php/20180731/mongodb.so (/usr/lib/php/20180731/mongodb.so: undefined symbol: ns_parserr), /usr/lib/php/20180731/mongodb.so.so (/usr/lib/php/20180731/mongodb.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[PHP Modules]
calendar
Core
ctype
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

@meshackjr
Copy link

If your using valet, restart it after installation.

@KR-CHOUDHARY
Copy link

Class "MongoDB\Driver\Manager" not found this error new laravel Version please help me
my new error in terminal error this PHP Warning: PHP Startup: Unable to load dynamic library 'mongodb' (tried: C:\xampp\php\ext\mongodb (The specified module could not be found), C:\xampp\php\ext\php_mongodb.dll (The specified module could not be found)) in Unknown on line 0
php version PHP 8.2.4
laravel version latest

@latifaChakir
Copy link

did you fixed this problem!

@KR-CHOUDHARY
Copy link

KR-CHOUDHARY commented Apr 6, 2024 via email

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

No branches or pull requests