mongodb / mongo-php-driver

The Official MongoDB PHP driver
https://pecl.php.net/package/mongodb
Apache License 2.0
882 stars 200 forks source link

requires ext-mongodb ^1.5.0 #874

Closed Barno closed 5 years ago

Barno commented 6 years ago

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

jmikola commented 6 years ago

If Composer is reporting "the requested PHP extension mongodb is missing from your system" but the extension does show up in phpinfo() output, I would confirm that Composer is running with the same PHP environment that reports the extension. You may have multiple PHP binaries on the system and/or may be mixing up the CLI with a web SAPI environment. Each PHP environment may have its own php.ini file and each PHP version has its own pecl command and development headers used for compiling the extension.

I can't use some functionality, like aggregateCursor

If you're referring to MongoCollection::aggregateCursor(), that method is only found in the legacy mongo extension. The PHP library's upgrade guide includes a table that matches methods found in the legacy extension with their equivalents in the current driver/library.

Likewise for the MongoClient class. The equivalents in the current driver and library are MongoDB\Driver\Manager and MongoDB\Client, respectively.

Barno commented 6 years ago

thanks for reply @jmikola I can see my php ini with php --ini

Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php7.2.1/conf Loaded Configuration File: /Applications/MAMP/bin/php/php7.2.1/conf/php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none)

inside /Applications/MAMP/bin/php/php7.2.1/conf/php.ini I can see

extension=mongodb.so and the version is 7.2.1

jmikola commented 6 years ago

composer diagnose may be helpful to determine the exact PHP binary used by Composer. It's quite possible that it's using macOS's default php binary or an alternative version installed from Homebrew, each of which may have their own php.ini file. Likewise, you should confirm the version of pecl used to install the extension (e.g. which pecl).

Barno commented 6 years ago

thanks again, you are right, I'm using default php. pecl version is:

PEAR Version: 1.10.5 PHP Version: 7.2.1 Zend Engine Version: 3.2.0

jmikola commented 6 years ago

@Barno: Did you sort this out on your end, or is this still an outstanding problem?

Assuming your intention is to run the extension/library from MAMP's PHP environment, the take-away from https://github.com/mongodb/mongo-php-driver/issues/874#issuecomment-403911019 was:

derickr commented 5 years ago

We are closing this ticket as there was no follow up since our last question. Feel free to re-open with more information if we are mistaken.

ayrasys commented 5 years ago

sudo apt-get install php-mongodb

imyuvii commented 5 years ago

do php -m and see if MongoDB extension is loaded.

rakeshmishrait commented 5 years ago

If we used php7.3 at ubuntu 18.10 on need to this command:- Open Terminal and run it.

sudo apt-get install php7.3-mongodb

michaelphipps commented 5 years ago

As of September 2019 sudo apt-get install php-mongodb does not install a high enough version of the php-mongodb extension on Ubuntu. By using the pecl install method, you will get the correct version.

If you don't have pecl installed:

sudo apt install php-pear
sudo apt install php-dev

Once pecl is installed: sudo pecl install mongodb

Finally, to easily add the extension to php: sudo phpenmod mongodb

alcaeus commented 5 years ago

@michaelphipps if you are having an issue, please consider opening a new issue instead of commenting on an old, unrelated issue. The version being installed depends heavily on the system you are using, which is why you need to include more information. The version being installed depends on your Ubuntu version (assuming you're not using a PPA):

Ubuntu Version ext-mongodb version
Xenial (16.04 LTS) 1.1.5
Bionic (18.04 LTS) 1.3.4
Cosmic (18.10) 1.5.2
Disco (19.04) 1.5.3
Eoan (upcoming 19.10) 1.5.5

If you are using ppa:ondrej/php, it will install 1.5.5 on all supported platforms (16.04, 18.04, 19.04).

For any other versions in use or issues, please create a new issue and include necessary information so we can debug this. Thanks!

vino-jasuba commented 5 years ago

As of September 2019 sudo apt-get install php-mongodb does not install a high enough version of the php-mongodb extension on Ubuntu. By using the pecl install method, you will get the correct version.

If you don't have pecl installed:

sudo apt install php-pear
sudo apt install php-dev

Once pecl is installed: sudo pecl install mongodb

Finally, to easily add the extension to php: sudo phpenmod mongodb

Thanks @michaelphipps , this worked 👍

oloriin commented 4 years ago

sudo add-apt-repository ppa:ondrej/php sudo apt-get install php-mongodb

emtiazzahid commented 4 years ago

macOS sudo pecl install mongodb

Note: it will add extension automatically you need to remove existing extension line from php.ini if already exist

kzenman commented 2 years ago

sudo apt-get install php7.3-mongodb

Worked for me in version 7.4 - sudo apt-get install php7.4-mongodb