- mongodb/mongodb 1.2.0 requires ext-mongodb ^1.3.0 -> the requested PHP extension mongodb is missing from your system
Composer is giving you the right answer there, you are using the wrong library. Don't use --ignore-platform-reqs, or you can, which to force install it. What you need to do now is check which library fits your php version. Write
php --version
if you don't know which one you are using. Output should be something like:
PHP 5.6.30-0+deb8u1 (cli) (built: Feb 8 2017 09:49:20)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
Find your version in the list below.
See the description in mongodb: PHP-Driver for mongodb
Head over to pecl and download whichever version fits your php version number.
in your case (PHP5.6):
$ wget https://pecl.php.net/get/mongodb-1.2.11.tgz
$ tar -xvzf mongodb-1.2.11.tgz
$ cd mongodb-1.2.11/
$ phpize
$ ./configure
$ make all -j 5
$ sudo make install
now it should work.
You can test the php mongodb connection with this code (finding an ObjectId) :
<?php
# filename ConnectMongo.php
require_once __DIR__ . "/vendor/autoload.php";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// connect to mongodb
$manager = new MongoDB\Driver\Manager('mongodb://username:password@host');
$id = new \MongoDB\BSON\ObjectId("5a0c8e2362eb6404c2f10032");
$filter = ['_id' => $id];
$options = [];
$query = new \MongoDB\Driver\Query($filter, $options);
$rows = $manager->executeQuery('db.collection', $query);
foreach ($rows as $document) {
var_dump($document);
}
?>
In terminal write this to test the connection:
$ php ConnectMongo.php
Make sure that you also install using composer, you should not get that same error anymore.