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

Viewed 1047

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?

2 Answers

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

Related