I am struggling with this. I had followed @Michael_Lynn’s Quickstart for PHP, but he is running on a local dev laptop.
I am trying to replicate with Docker containers. I thought I had it when I ONLY required the MongoDB extension, as I had to change (hard-code) some values to /usr/bin
. But now I need the next composer
package, zlucas/phpdotenv
which breaks the config above.
Right now, the nearest I got was to use my own customer Docker Image with:
FROM php:8.0-apache
RUN apt-get update -y && apt-get upgrade -y && apt-get install git libssl-dev -y
RUN pecl install mongodb && docker-php-ext-enable mongodb
RUN echo "extension=mongodb.so" >> /usr/local/etc/php/php.ini
COPY --from=composer /usr/bin/composer /usr/bin/composer
EXPOSE 80 443
This is deployed as a container with the following docker-compose.yml
config:
version: '2'
services:
php:
image: redswitch/php-mongodb:8.0-1.9.0-3
container_name: php
volumes:
- ./html:/var/www/html
restart: always
environment:
- VIRTUAL_HOST=www.domain.com
- LETSENCRYPT_HOST=www.domain.com
- LETSENCRYPT_EMAIL=admin@domain.com
- "TZ=Europe/London"
ports:
- 80
expose:
- 80
restart: unless-stopped
composer:
image: composer:2.0
command: ["composer", "install"]
volumes:
- ./html:/app
networks:
default:
external:
name: nginx-proxy-net
In the ./html
folder is composer.json
:
{
"require": {
"mongodb/mongodb": "^1.9.0-alpha1",
"vlucas/phpdotenv": "^5.3.0"
}
}
I have tried different minimum versions, such as ^1.8.0
, ^1.9.0
and the above. This provides variances of the same error message depending upon which version is specified in the composer.json
file.
The composer
container starts and stops, as expected. This is the container’s log:
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.,
Loading composer repositories with package information,
Updating dependencies,
Your requirements could not be resolved to an installable set of packages.,
,
Problem 1,
- Root composer.json requires mongodb/mongodb ^1.9.0-alpha1 -> satisfiable by mongodb/mongodb[1.9.0-alpha1].,
- mongodb/mongodb 1.9.0-alpha1 requires ext-mongodb ^1.10.0 -> it is missing from your system. Install or enable PHP's mongodb extension.,
,
To enable extensions, verify that they are enabled in your .ini files:,
- /usr/local/etc/php/php-cli.ini,
- /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini,
- /usr/local/etc/php/conf.d/docker-php-ext-zip.ini,
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.,
Checking the php
container with a phpinfo()
call, I can see that the MongoDB extension v1.9.0 is enabled, with a loaded config file and additional config at:
- /usr/local/etc/php/php.ini
- /usr/local/etc/php/conf.d/docker-php-ext-mongodb.ini, /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
How do I overcome this issue?
Is this the correct way to deploy PHP+MongoDB+Composer+PHPDotEnv?