docker-library / php

Docker Official Image packaging for PHP
https://php.net
MIT License
3.84k stars 2k forks source link

Unable to install extensions mbstring/openssl/pdo_mysql on php:8.1-fpm-alpine v.3.20 #1515

Closed kamyweb closed 6 months ago

kamyweb commented 6 months ago

Unable to build our custom Dockerfile based on php:8.1-fpm-alpine after the upgrade of Alpine to ver. 3.20 Dockerfile:

FROM php:8.1-fpm-alpine

RUN apk update && \
    apk add autoconf build-base g++ gcc git make wget zip \
    libmcrypt-dev \
    libmemcached-dev \
    libzip-dev \
    openssl-dev \
    php81-openssl \
    php81-pdo_mysql \
    php81-mbstring

Error:

#6 0.178 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
#6 0.244 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/x86_64/APKINDEX.tar.gz
#6 0.465 v3.20.0-2-g567460db635 [https://dl-cdn.alpinelinux.org/alpine/v3.20/main]
#6 0.465 v3.20.0-1-g69f729b14d3 [https://dl-cdn.alpinelinux.org/alpine/v3.20/community]
#6 0.465 OK: 24143 distinct packages available
#6 0.723 ERROR: unable to select packages:
#6 0.723   php81-mbstring (no such package):
#6 0.723     required by: world[php81-mbstring]
#6 0.723   php81-openssl (no such package):
#6 0.723     required by: world[php81-openssl]
#6 0.723   php81-pdo_mysql (no such package):
#6 0.723     required by: world[php81-pdo_mysql]

Following this link it seems Alpine drop support to php81 on v.3.20, isn't it? https://pkgs.alpinelinux.org/packages?name=*php81*&branch=v3.20&repo=&arch=x86_64&maintainer=

In this case, it makes sense to build a php81 docker image based on distro version that drop support to it?

Temporary solution is using php:8.1-fpm-alpine3.18

jnoordsij commented 6 months ago

Hey there!

Your problem is caused by the fact that you're accidentally mixing two PHP installation by using apk to install PHP extensions, as this will actually add an entire new PHP installation to the resulting image, rather than using the bundled one. To install additional extensions to this image, you could use the bundled docker-php-ext-install script. Given that mbstring and openssl are already part of the base image, something along the following lines should work:

FROM php:8.1-fpm-alpine

RUN apk add --no-cache <packages-you-need> && \
    docker-php-ext-install -j$(nproc) pdo_mysql && \
    php -m # smoketest

See also https://github.com/docker-library/docs/tree/master/php#how-to-install-more-php-extensions if you're looking for additional details.