How to compile AMQP extension for PHP 8.0 via Multistage Dockerfile

How to compile AMQP extension for PHP 8.0 via Multistage Dockerfile

Why do this?

2020-12-03 there is no PECL AMQP extension compatible with PHP 8.0 so you cannot use docker-php-ext-install amqp & docker-php-ext-enable amqp

Latest version 1.10.2 is compatible with PHP < 8. So you have to use dev version from Github and build it from source code from master branch.

https://pecl.php.net/package/amqp

Dockerfile

FROM php:8.0-fpm-alpine AS ext-amqp

ENV EXT_AMQP_VERSION=master

RUN docker-php-source extract \
    && apk -Uu add git rabbitmq-c-dev \
    && git clone --branch $EXT_AMQP_VERSION --depth 1 https://github.com/php-amqp/php-amqp.git /usr/src/php/ext/amqp \
    && cd /usr/src/php/ext/amqp && git submodule update --init \
    && docker-php-ext-install amqp
    
RUN ls -al /usr/local/lib/php/extensions/
    
FROM php:8.0-fpm-alpine

COPY --from=ext-amqp /usr/local/etc/php/conf.d/docker-php-ext-amqp.ini /usr/local/etc/php/conf.d/docker-php-ext-amqp.ini
COPY --from=ext-amqp /usr/local/lib/php/extensions/no-debug-non-zts-20200930/amqp.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/amqp.so

...

docker build .