Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 7 with Doctrine MongoDB ODM

I have a Symfony 2 application that is using Doctrine MongoDB ODM and I'm trying to get this running with PHP 7.

I have installed PHP 7 successfully but installing dependencies through Composer is giving me grief with the following error:

doctrine/mongodb 1.0.x-dev requires ext-mongo >=1.2.12,<1.7-dev -> the requested PHP extension mongo is missing from your system.

I managed to install the PHP 7 mongo extension through apt:

apt-get install php7.0-mongo

Just to be sure, I have also installed the mongodb extension through PECL:

sudo apt-get install -y php-pear php7.0-dev libcurl3-openssl-dev
sudo pecl install mongodb

However, I'm still get the error that the mongo extension cannot be found. There seems to be a version discrepancy in that ext-mongo >=1.2.12 is required but only 1.1.6 was installed::

$ php -i | grep mongo
/etc/php/7.0/cli/conf.d/20-mongodb.ini,
mongodb
mongodb support => enabled
mongodb version => 1.1.6
mongodb stability => stable
libmongoc version => 1.3.5
mongodb.debug => no value => no value

What is the correct way to install the mongo extension required by Doctrine ODM for PHP 7?

like image 837
Luke Avatar asked May 01 '16 07:05

Luke


2 Answers

On PHP7 you cannot install mongo extension. What you can do, is to install https://github.com/alcaeus/mongo-php-adapter first, then install doctrine.

composer require alcaeus/mongo-php-adapter
like image 165
malcolm Avatar answered Nov 03 '22 16:11

malcolm


in composer.json I added

"provide" : {
  "ext-mongo": "*"
},

before "require" and this forces to install latest extension

like image 45
cwhisperer Avatar answered Nov 03 '22 17:11

cwhisperer