skip to Main Content

I’m trying to upgrade an Alpine image from PHP 7.4 to PHP 8.1.

This is the Dockerfile:

FROM php:8.1-fpm-alpine
RUN apk update && 
    apk add bash build-base gcc wget git autoconf libmcrypt-dev 
    g++ make openssl-dev 
    php8-openssl 
    php8-pdo_mysql 
    php8-mbstring 
    php8-mcrypt

The errors I get are those:

#7 3.780   php8-mbstring (no such package):
#7 3.780 ERROR: unable to select packages:
#7 3.867     required by: world[php8-mbstring]
#7 3.867   php8-mcrypt (no such package):
#7 3.867     required by: world[php8-mcrypt]
#7 3.867   php8-openssl (no such package):
#7 3.867     required by: world[php8-openssl]
#7 3.867   php8-pdo_mysql (no such package):
#7 3.867     required by: world[php8-pdo_mysql]

How can install these extensions?

I also tried to add main and community repos, but without success:

FROM php:8.1-fpm-alpine

RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories
RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories

RUN apk update && 
    apk add bash build-base gcc wget git autoconf libmcrypt-dev 
...

2

Answers


  1. Chosen as BEST ANSWER

    As pointed out by elburro1887, there is no package php81-mcrypt in the list of packages available for Alpine.

    The reason was explained by Álvaro González in the comments to my question

    mcrypt had been abandoned for years and it was removed in PHP/7.2. There's no way to use it in PHP/8.1.

    So, I ended up using PECl in the meantime (I think the library should be removed and substituted with something else) and this is the resulting working Dockerfile:

    FROM php:8.1-fpm-alpine
    ARG xdebug_enabled=false
    
    RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories
    RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories
    
    # installing required extensions
    RUN apk update && 
        apk add bash build-base gcc wget git autoconf libmcrypt-dev libzip-dev zip 
        g++ make openssl-dev 
        php81-openssl 
        php81-pdo_mysql 
        php81-mbstring
    
    RUN pecl install mcrypt && 
        docker-php-ext-enable mcrypt
    
    ...
    

    Thank you to all of you for the support!


  2. The Alpine packages for PHP 8.1 look like "php81-xxx".

    Here you can see a list of the available packages for Alpine:

    It seems there is no package called php81-mcrypt. There is a package called php81-pecl-mcrypt, but I’m not sure if it’s the one you want.

    So removing mcrypt, this would be a working Dockerfile:

    FROM php:8.1-fpm-alpine
    RUN apk update && 
        apk add bash build-base gcc wget git autoconf libmcrypt-dev 
        g++ make openssl-dev 
        php81-openssl 
        php81-pdo_mysql 
        php81-mbstring
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search