Yannick Pereira-Reis bio photo

Yannick Pereira-Reis

DevOps (docker swarm, haproxy, CI/CD, ELK, prometheus, grafana, ansible, automation, RabbitMQ, LVM, MySQL replication...) and fullstack web developer Symfony 2/3/4/5 + VueJs in Valence (France).

Twitter LinkedIn Github

When working with docker, a common thing is to use a specific docker image/container to run composer. And it can be a good thing to run composer through HHVM to increase performance.

Symfony

Composer and DoctrineMongoDBBundle

But if you try to install DoctrineMongoDBBundle thanks to this kind of composer container (php + composer + hhvm), you will probably have this error:

$ make composer-update "doctrine/mongodb-odm doctrine/mongodb-odm-bundle"
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - doctrine/mongodb 1.2.0 requires ext-mongo ^1.2.12 -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.2.0 requires ext-mongo ^1.2.12 -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.2.0 requires ext-mongo ^1.2.12 -> the requested PHP extension mongo is missing from your system.
    - Installation request for doctrine/mongodb == 1.2.0.0 -> satisfiable by doctrine/mongodb[1.2.0].

This is because composer (by default) checks if you have the good extensions installed for your project. And the container used to run composer is not the container we use to run our project.

The two ways I know to avoid/fix this problem are:

  • Adding the --ignore-platform-reqs option to the composer command.
$ composer install --ignore-platform-reqs
  • Installing the mongo php extension in the composer container.
$ apt-get install php5-mongo

But if you use composer with HHVM, the second solution will not work because HHVM won’t detect installed PHP extensions like with “normal” PHP.

So I advise you to use the first solution: --ignore-platform-reqs

Important 1

You need to install php5-mongo extension in your app container !

Important 2

Of course the previous explanation is valid for any other PHP extensions, not only php5-mongo !