Search code examples
dockerdockerfilerabbitmq

Errors creating Docker containers using PHP 8.2 an AMQP for RabbitMQ


I am trying to start a Symfony project using Docker, PHP 8.2 and including AMQP to the formula but I am unable to install it, here is my Dockerfile:

FROM php:8.2.15-fpm

ARG UID
EXPOSE $UID

# Create user and some useful stuff
RUN adduser -u ${UID} --disabled-password --gecos "" appuser
RUN mkdir /home/appuser/.ssh
RUN chown -R appuser:appuser /home/appuser/
RUN echo "StrictHostKeyChecking no" >> /home/appuser/.ssh/config
RUN echo "export COLUMNS=300" >> /home/appuser/.bashrc
RUN echo "alias sf=/appdata/www/bin/console" >> /home/appuser/.bashrc

# Install packages and PHP extensions
RUN apt update \
    && apt install -y git acl openssl openssh-client wget zip vim libssh-dev \
    && apt install -y libpng-dev zlib1g-dev libzip-dev libxml2-dev libicu-dev \
    && docker-php-ext-install intl pdo pdo_mysql zip \
    && pecl install amqp xdebug \
    && docker-php-ext-enable --ini-name 05-opcache.ini opcache amqp xdebug

# Install and update Composer
RUN curl https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
RUN composer self-update

# Install PHP-CS-FIXER
RUN wget https://cs.symfony.com/download/php-cs-fixer-v3.phar -O php-cs-fixer
RUN chmod a+x php-cs-fixer
RUN mv php-cs-fixer /usr/local/bin/php-cs-fixer

# Install Symfony Binary
USER appuser
RUN wget https://get.symfony.com/cli/installer -O - | bash
USER root

RUN mkdir -p /appdata/www

# Config XDEBUG
COPY ./xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

WORKDIR /appdata/www

The problem take place in this lines when it tries to install and active AMQP:

&& pecl install amqp xdebug \
&& docker-php-ext-enable --ini-name 05-opcache.ini opcache amqp xdebug

Acording with the logs, the Dockerfile download the version 2.1.2 of AMQP (the last one available). This is the error message:

57.17 checking for amqp using pkg-config... configure: error: librabbitmq not found
57.19 ERROR: `/tmp/pear/temp/amqp/configure --with-php-config=/usr/local/bin/php-config --with-librabbitmq-dir' failed

I think the key is "librabbitmq not found", because looking in the repository the instructions say that it is necesary to have install "librabbitmq".

I have been checking the instructions to install "librabbitmq" but I am not really sure how to do it, the instructions are unclear for me. Do I have to clone the repo and follow the instructions? In that case, where do I have to do it exactly? I am using WSL with Ubuntu 22.04.

Finally, I have to say that if I remove the word "amqp" both in "pecl install" and "docker-php-ext-enable", the Dockerfile works.

On the other hands, this problem with PHP 7 does not happen.

Thanks.

UPDATE

I managed to install "librabbitmq" but I am still getting the same error "librabbitmq not found".


Solution

  • You need to install the librabbitmq-dev package. Here's a revised Dockerfile. I have stripped out a few things that don't relate to the problem at hand. You can consolidate the two RUN commands once you are satisfied that AMQP is being installed successfully.

    FROM php:8.2.15-fpm
    
    RUN apt update \
        && apt install -y git acl openssl openssh-client wget zip vim libssh-dev \
        && apt install -y libpng-dev zlib1g-dev libzip-dev libxml2-dev libicu-dev \
        && docker-php-ext-install intl pdo pdo_mysql zip
        
    RUN apt install -y librabbitmq-dev \
        && pecl install amqp xdebug \
        && docker-php-ext-enable --ini-name 05-opcache.ini opcache amqp xdebug