Search code examples
phpdockerdockerfileimapphp-8.4

Error on PHP 8.4-fpm IMAP package install with Dockerfile


In my Dockerfile for php8.4-fpm i am installing IMAP package with the following commands:

FROM php:8.4-fpm
[...]
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
    docker-php-ext-install imap

But got an error:

process "/bin/sh -c docker-php-ext-configure imap --with-kerberos --with-imap-ssl" did not complete successfully: exit code: 1

How to solve it?


Solution

  • OK. Solved. I found that since PHP 8.4 the IMAP extension is no longer part of PHP Core, and has moved to PECL.

    So the solution to install IMAP package for PHP since 8.4 version from Dockerfile is:

    RUN pecl install imap && \
        docker-php-ext-enable imap
    

    Also if you do not use docker but just a native SSH commands on a Debian/Ubuntu. You should use these commands:

    sudo apt-get install libc-client-dev libkrb5-dev
    
    # may be on some systems you need this
    sudo ln -s /usr/lib/x86_64-linux-gnu/libkrb5.so /usr/lib/
    sudo ln -s /usr/lib/x86_64-linux-gnu/libc-client.so /usr/lib/
    
    pecl install imap
    echo "extension=imap.so" | sudo tee -a /etc/php/8.4/cli/php.ini
    echo "extension=imap.so" | sudo tee -a /etc/php/8.4/fpm/php.ini
    sudo systemctl restart php8.4-fpm
    
    # check imap is installed
    php -m | grep imap
    

    Hope that helps!