Php: docker-php-ext-install vs pecl

Created on 14 Feb 2017  路  10Comments  路  Source: docker-library/php

What's the point of using docker-php-ext-configure and docker-php-ext-install over pecl? I see people use it to install extensions that are available on pecl. Why manually clone a repository and configure if you can do it with just pecl install?

Most helpful comment

Wow, I didn't expect to get so many downvotes on my last comment :) I guess I owe some explanations.

Script docker-php-ext-install used to build extensions from code (and enable after), mostly used to install core extensions. If you want to install a third-party extension, most likely it's already published on pecl and should be installed via pecl install [extension]. But before installing extensions via pecl you should set a path to php.ini for pecl by running:

pecl config-set php_ini "${PHP_INI_DIR}/php.ini"

Note, that unlike docker-php-ext-install command pecl install will not enable your extension after installation, so you'll have to run docker-php-ext-enable [extension] after. If for some reason you can't install your extension via pecl you can always install it from code by using docker-php-ext-install.

Script docker-php-ext-configure executed automatically in docker-php-ext-install, so no need to run it directly unless you want to pass through specific flags for ./configure.

TL;DR: you can find all examples with extensions installation in Dockerfiles of wodby/php image.

All 10 comments

I figured it out

I asked about this on stack overflow but this question was very badly received

https://stackoverflow.com/questions/49894623/why-docker-php-ext-install-does-not-contains-some-extensions-and-has-it-advanta

Has anyone can compare docker-php-ext-install and pecl?

Wow, I didn't expect to get so many downvotes on my last comment :) I guess I owe some explanations.

Script docker-php-ext-install used to build extensions from code (and enable after), mostly used to install core extensions. If you want to install a third-party extension, most likely it's already published on pecl and should be installed via pecl install [extension]. But before installing extensions via pecl you should set a path to php.ini for pecl by running:

pecl config-set php_ini "${PHP_INI_DIR}/php.ini"

Note, that unlike docker-php-ext-install command pecl install will not enable your extension after installation, so you'll have to run docker-php-ext-enable [extension] after. If for some reason you can't install your extension via pecl you can always install it from code by using docker-php-ext-install.

Script docker-php-ext-configure executed automatically in docker-php-ext-install, so no need to run it directly unless you want to pass through specific flags for ./configure.

TL;DR: you can find all examples with extensions installation in Dockerfiles of wodby/php image.

@csandanov Any idea how to configure an extension I installed using pecl install? docker-php-ext-configure doesn't recognize such extension and fails like this: https://gist.github.com/enumag/fccf3d7182b421c4226d85af68b2bc9e

@enumag, docker-php-ext-configure is mostly for extensions bundled with the php source or manually downloaded. As far as I understand it, you'd have to tell pecl install any configure options, but they don't seem to have that option.

I think adapting this redis comment should work https://github.com/phpredis/phpredis/issues/1176#issuecomment-558787347. I had to use the full path to the module. So roughly something like this:

RUN set -eux; \
    # install dependencies
    apt-get update; \
    apt-get install -y --no-install-recommends libevent-dev libssl-dev; \
    # configure: error: Couldn't find /usr/local/include/php/sockets/php_sockets.h.
    docker-php-ext-install sockets; \
    cd /usr/src/; \
    # download event, should probably specify version number
    pecl bundle event; \
    # configure and install using the full path
    docker-php-ext-configure /usr/src/event [args here]; \
    docker-php-ext-install /usr/src/event; \
    # TODO: cleanup
    # make sure the module shows up
    php -m | grep event

@yosifkit Just noticed that you're using pecl bundle event instead of pecl install event. What's the reason / difference?

pecl bundle downloads the source instead of doing the full configure+install dance for you (which is why he does pecl bundle followed by an explicit docker-php-ext-configure and docker-php-ext-install) -- if you don't need custom configure flags for the module you're installing, doing pecl install followed by docker-php-ext-enable should be plenty.

Through some link hopping I ended up here and I really like @yosifkit his approach using pecl bundle. In case anybody else comes across this, two variations I made using redis as an example that also includes doing cleanup:

Using PHP source

RUN docker-php-source extract \
 && pecl bundle -d /usr/src/php/ext redis \
 && docker-php-ext-configure redis --enable-redis-igbinary \
 && docker-php-ext-install -j$(nproc) redis \
 && docker-php-source delete

Using /usr/local/src

RUN mkdir -p /usr/local/src/pecl \
 && pecl bundle -d /usr/local/src/pecl redis \
 && docker-php-ext-configure /usr/local/src/pecl/redis --enable-redis-igbinary \
 && docker-php-ext-install -j$(nproc) /usr/local/src/pecl/redis \
 && rm -rf /usr/local/src/pecl

We have a requirement to install extensions : memcached,msgpack,imagick and igbinary.
We also have an internal repository where all these extensions exists.

We are restricted to use the internal repository as our build nodes do not have internal connection.
But as far as I understand, running command "RUN pecl install memcached" needs internal connection.

So how can we go ahead and install these extensions from our internal repository ?

Also, I am putting our repository URL into source.list, so that apt-get install installs the packages for this repository .

@Surbhi27946 I would recommend downloading the necessary tarballs from https://pecl.php.net/ and storing them on an internal server

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

Was this page helpful?
0 / 5 - 0 ratings