Guidance: Install Couchbase SDK on PHP alpine official docker image

Hello,

I’m looking for some guidance on the most reliable way to install Couchbase on PHP Alpine official image https://hub.docker.com/_/php

For now this is what I do:

FROM php:8.2-fpm-alpine3.16
RUN echo "Installing PECL extensions..." \
    && apk --no-cache --update add \
        build-base autoconf \
        libcouchbase libcouchbase-dev \
    && pecl install couchbase-3.2.2 1>/dev/null \
    && docker-php-ext-enable couchbase 1>/dev/null \
    && apk del \
        build-base autoconf \
        libcouchbase-dev 1>/dev/null \
    && echo "-> Done"

But this takes a very long time to build and I’m trying to upgrade to PHP 8.4 and Couchbase SDK 4 and it doesn’t work anymore.
I see in the alpine official package list that there is already a couchbase.so build for this version which I would like to use: php84-pecl-couchbase - Alpine Linux packages

But I can’t find how to enable it as even moving it to the right extension folder doesn’t load it so rather than following through this manual approach I would like to know if you can tell me if you have a guide on how to install it on PHP Alpine official image?

Thank you for your time on this.
Lucas

Hi @LucasH,

If possible, I would suggest using the precompiled binaries which can be found here, the ones labeled musl are Alpine compatible.

Something like this worked for me:

FROM php:8.2-fpm-alpine3.16

ENV COUCHBASE_VERSION=4.2.5
ENV PHP_VERSION=php8.2
ENV COUCHBASE_BINARY=couchbase-${COUCHBASE_VERSION}-${PHP_VERSION}-nts-linux-musl-x86_64
ENV COUCHBASE_DOWNLOAD_URL=https://packages.couchbase.com/clients/php/${COUCHBASE_BINARY}.tgz

RUN apk add --no-cache --update \
    curl \
    tar \
    libssl3 \
    libstdc++

RUN curl -fsSL ${COUCHBASE_DOWNLOAD_URL} -o /tmp/${COUCHBASE_BINARY}.tgz && \
    mkdir -p /tmp/couchbase && \
    tar -xzf /tmp/${COUCHBASE_BINARY}.tgz -C /tmp/couchbase && \
    cp /tmp/couchbase/${COUCHBASE_BINARY}/couchbase.so $(php-config --extension-dir) && \
    cp /tmp/couchbase/${COUCHBASE_BINARY}/90-couchbase.ini $PHP_INI_DIR/conf.d/

CMD ["php", "-m"]

Hope that helps.

1 Like