'How to install ZeroMQ for PHP on an Alpine Linux container?

To be able to push notifications via WebSockets from PHP using Ratchet, I need to install ZeroMQ as stated in the documentation. However I didn't find any information about how to do it for Alpine Linux. Most of the time what we can find is with apt-get, for example here. Same about the Docker images (Dockerfile) available on Docker hub.

Since the dependencies and their name seem different, how to do it with Alpine?



Solution 1:[1]

For those who face the same situation, I finally found how to do it:

FROM php:7-cli-alpine
RUN apk add autoconf gcc libzmq zeromq-dev zeromq coreutils build-base
RUN pecl install zmq-beta \
   && docker-php-ext-enable zmq

Source: https://smartango.com/2018/10/php-zmq-in-docker-and-checking-whether-the-c-compiler-works-no/

Solution 2:[2]

In php:8.0-fpm-alpine, pecl install zmq-beta threw an error and failed to compile, so I used this command:

FROM php:8.0-fpm-alpine
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN set -eux && \
  apk add --update-cache --no-cache libzmq zeromq-dev zeromq && \
  apk add --update-cache --no-cache --virtual=.build-php-dependencies \
  autoconf gcc coreutils build-base git && \
  git clone https://github.com/mkoppanen/php-zmq.git && \
  cd php-zmq && \
  phpize && \
  ./configure && \
  make && \
  make install && \
  docker-php-ext-enable zmq && \
  apk del .build-php-dependencies

Reference:
https://github.com/zeromq/php-zmq/issues/200#issuecomment-610161524

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kwadz
Solution 2