Installing PHP extensions without pecl in PHP 8 Docker images

I discovered recently that pecl is no longer shipped in the PHP Docker images for PHP 8. This appears to be related to the deprecation of --with-pear in PHP core as noted in issue 1029.

Consider this Dockerfile:

FROM php:8.0.0RC5-cli-buster

RUN pecl install mongodb && docker-php-ext-enable mongodb

If you build, you’ll discover the pecl cannot be found:

$ docker build -t project1 .
Sending build context to Docker daemon   2.56kB
Step 1/2 : FROM php:8.0.0RC5-cli-buster
 ---> 8b1f24a39f30
Step 2/2 : RUN pecl install mongodb && docker-php-ext-enable mongodb
 ---> Running in c013519c47f9
/bin/sh: 1: pecl: not found
The command '/bin/sh -c pecl install mongodb && docker-php-ext-enable mongodb' returned a non-zero code: 127

Fortunately, we can get the source from pecl.php.net ourselves and install it:

FROM php:8.0.0RC5-cli-buster

RUN mkdir -p /usr/src/php/ext/mongodb \
    && curl -fsSL https://pecl.php.net/get/mongodb | tar xvz -C "/usr/src/php/ext/mongodb" --strip 1 \
    && docker-php-ext-install mongodb

As of this writing, it will install version 1.9.0RC1 which is required for PHP 8 anyway, but you can specify the version by adding it to the URL like this: https://ift.tt/2KCPMXp

docker build now works.

Job done!

from Rob Allen’s DevNotes https://ift.tt/39fmGHN
via IFTTT

Leave a Reply

Back to Top