Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why docker-php-ext-install does not contains some extensions, and has it advantages over pecl?

Lets consider these commands:

We starting docker image with php 7.2 based on alpine.

docker run -it php:7.2-fpm-alpine3.7 sh

We trying to install php-mongodb as any other extension

docker-php-ext-install mongodb

But we obtaining error:

error: /usr/src/php/ext/mongodb does not exist

usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name 
...]
   ie: /usr/local/bin/docker-php-ext-install gd mysqli
       /usr/local/bin/docker-php-ext-install pdo pdo_mysql
       /usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop

if custom ./configure arguments are necessary, see docker-php-ext-configure

Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zend_test zip

Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.

I found some images of php with installed mongodb drivers:

https://github.com/Vinelab/docker-php-mongo

https://gist.github.com/ebuildy/ba6820cbe1befaa229d2

https://hub.docker.com/r/spittet/php-mongodb/

All with the same command:

pecl install mongodb

Have docker-php-ext-install any advantages over pecl? I saw that most extensions is installed by docker-php-ext-install. I found this question without answer in issue:

https://github.com/docker-library/php/issues/374

If pecl contains all extensions, but docker-php-ext-install allow to install constrained list, why it was created?

like image 612
Daniel Avatar asked Apr 18 '18 08:04

Daniel


4 Answers

The answer may become irrelevant to the question. Still, I am adding the following snippet in case someone comes here as I did and can install mongodb extension for php in a docker container. I am using php7.3-fpm. https://www.php.net/manual/en/mongodb.installation.pecl.php

RUN pecl install mongodb \
    &&  echo "extension=mongodb.so" > $PHP_INI_DIR/conf.d/mongo.ini
like image 173
ssi-anik Avatar answered Nov 07 '22 19:11

ssi-anik


You can find explanations in docker-php-ext-install vs pecl issue in the official php image repository

like image 42
chingis Avatar answered Nov 07 '22 17:11

chingis


I am using this command lines and working for me. Get docker container id with docker ps command and docker exec -it <container id> bash

apt-get update
apt-get install openssl libssl-dev libcurl4-openssl-dev
pecl install mongo
echo "extension=mongo.so" > /usr/local/etc/php/conf.d/mongo.ini
like image 2
Toir Avatar answered Nov 07 '22 17:11

Toir


My docker kept complaining that it could not find the mongo.so extension. Finally i figured it out to run the following

RUN apt-get install  -y openssl libssl-dev libcurl4-openssl-dev
RUN pecl install mongodb-1.6.0
RUN docker-php-ext-enable /usr/local/lib/php/extensions/no-debug-non-zts-20180731/mongodb.so

It seems like docker wants that you enable a php extension via docker-php-ext-enable

like image 3
erwinnandpersad Avatar answered Nov 07 '22 17:11

erwinnandpersad