3
votes

I installed ext-mongodb

php --ri mongodb | grep version

MongoDB extension version => 1.5.1 
libbson bundled version => 1.11.0
libmongoc bundled version => 1.11.0

I have an issue with composer when I do composer install

- mongodb/mongodb 1.4.0 requires ext-mongodb ^1.5.0 -> the requested PHP extension mongodb is missing from your system.
- mongodb/mongodb 1.3.2 requires ext-mongodb ^1.4.0 -> the requested PHP extension mongodb is missing from your system.
- mongodb/mongodb 1.3.1 requires ext-mongodb ^1.4.0 -> the requested PHP extension mongodb is missing from your system.
- mongodb/mongodb 1.3.0 requires ext-mongodb ^1.4.0 -> the requested PHP extension mongodb is missing from your system.
- mongodb/mongodb 1.4.0 requires ext-mongodb ^1.5.0 -> the requested PHP extension mongodb is missing from your system.

My php Info (more details)

mongodb
MongoDB support enabled
MongoDB extension version   1.5.1
MongoDB extension stability stable
libbson bundled version 1.11.0
libmongoc bundled version   1.11.0
libmongoc SSL   enabled
libmongoc SSL library   Secure Transport
libmongoc crypto    enabled
libmongoc crypto library    Common Crypto
libmongoc crypto system profile disabled
libmongoc SASL  enabled
libmongoc ICU   disabled
libmongoc compression   enabled
libmongoc compression snappy    disabled
libmongoc compression zlib  enabled

If I try to install mongodb with composer

composer require mongodb/mongodb I have that error

If I use ( and I don't want use this method )

composer install --ignore-platform-reqs

I can see

    "mongodb/mongodb": "^1.3",

But in This way I can't use some functionality, like aggregateCursor

Attempted to call an undefined method named "aggregateCursor" of class "MongoDB\Collection"

or I can't use $m = new \MongoClient();

Attempted to load class "MongoClient" from the global namespace.

For connect to mongoDb I have to use

new \MongoDB\Client

I Use Symfony, but I don't think that it's relevant

Composer version 1.6.5 2018-05-04 11:44:5

PHP 7.2.1 (cli) (built: Jan 15 2018 12:20:50) ( NTS ) Copyright (c) 1997-2017 The PHP Group

2
sounds weird. only thing I can imagine ... is composer using a different php runtime and/or ini / config. but that's from a purely theoretical standpoint, hence no further practical advice ;o/Jakumi

2 Answers

7
votes

Following the below steps, it will work.

sudo apt-get install php7.2-dev
sudo apt-get install libcurl4-openssl-dev pkg-config libssl-dev libsslcommon2-dev
sudo apt-get install php-pear
sudo pecl install mongodb

Goto php.ini file

 extension=mongodb.so
3
votes

For Debian based operating system use following command

  sudo apt-get install php-mongodb