Installing PHP extensions without pecl in PHP 8 Docker images
UPDATE: Since this was published, PR 1087 has been raised and merged with restores pecl to the Docker PHP 8 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://pecl.php.net/get/mongodb-1.9.0RC1
docker build now works.
Job done!