PHP 7 with Doctrine MongoDB ODM
Asked Answered
H

3

6

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?

Hungnam answered 1/5, 2016 at 7:24 Comment(0)
S
17

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
Shamrock answered 2/5, 2016 at 17:35 Comment(4)
Ah. OK. So, if I understand correctly, as of this time of writing, Doctrine MongoDB ODM doesn't work on PHP 7. Is that correct?Hungnam
That isn't correct, Doctrine Mongodb ODM at the moment depend on old mongo extension, but works very well on PHP 7 with mongo-php-adapter package installed in project, and mongodb php extension.Shamrock
Yes. You're right that there is a "third-party" workaround, but Doctrine MongoDB ODM itself doesn't seem to work on PHP 7. I'm concerned about the "Known issues" of the mongo-php-adapter though, but I obviously have to try first... Thanks for your answer.Hungnam
I'm working on updating a project which already uses doctrine, if you don't want to remove doctrine, require mongo-php-adapter and require doctrine again you can use the --ignore-platform-reqs option: composer require alcaeus/mongo-php-adapter --ignore-platform-reqsKoehn
G
11

in composer.json I added

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

before "require" and this forces to install latest extension

Gregoor answered 14/8, 2016 at 11:25 Comment(0)
G
-3

In order to use Symfony with MongoDB you need:

  • Symfony : obviously :-) ;
  • Symfony Doctrine MongoDB Bundle (doctrine/mongodb-odm-bundle): this bundle integrates the Doctrine2 MongoDB Object Document Mapper (ODM) library into Symfony;
  • Doctrine MongoDB Object Document Mapper (doctrine/mongodb-odm): library that provides a PHP object mapping functionality for MongoDB;
  • MongoDB Adapter (alcaeus/mongo-php-adapter): It provides the API of ext-mongo built on top of mongo-php-library, thus being compatible with PHP 7;
  • MongoDB driver library (mongodb/mongodb): provides a high-level abstraction around the lower-level drivers for PHP;
  • MongoDB PHP extension: low level driver extension for PHP and HHVM. Please pay attention on the MongoDB driver. Don’t use the legacy MongoDB driver (http://php.net/manual/en/book.mongo.php).

You can follow the instructions here: "How to install Symfony3 with MongoDB"

It was written for Symfony3 but for Symfony2 is the same issue. The problem was PHP7 + mongodb driver + Doctrine.

Gimp answered 21/10, 2016 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.