phpdockermemcachedlibmemcached

Problem adding Memcached support in Docker for PHP8.1 using bookworm


I have a Dockerfile relying on PHP:8.1-apache, running since months.

Once PHP:8.1-apache started to use Debian bookworm, the memcached client started to give an error while building the image.

The Dockerfile rows involved are

FROM php:8.1-apache

...

RUN apt-get update --fix-missing -q \
    && apt-get install -y curl mcrypt gnupg build-essential software-properties-common wget vim zip unzip libxml2-dev libz-dev libpng-dev libmemcached-dev \
    && pecl install memcached \
    && docker-php-ext-enable memcached \

...

The error at image build time is:

checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located
ERROR: `/tmp/pear/temp/memcached/configure --with-php-config=/usr/local/bin/php-config --with-libmemcached-dir=no --with-zlib-dir=no --with-system-fastlz=no --enable-memcached-igbinary=no --enable-memcached-msgpack=no --enable-memcached-json=no --enable-memcached-protocol=no --enable-memcached-sasl=yes --enable-memcached-session=yes' failed

Pinning the oldstable version solves the problem,

FROM php:8.1-apache-bullseye

And that clearly indicates that the issue is caused by the switch to new Debian Version.

What could be done to use bookworm and continue to use the same libraries and process ?


Solution

  • Ensure these libraries are installed (in particular, libssl-dev):

    RUN apt install -y libmemcached-dev zlib1g-dev libssl-dev
    

    Credit to AKorezin: https://github.com/php-memcached-dev/php-memcached/issues/541#issuecomment-1624041385

    Then you can follow the usual PECL install process:

    RUN yes '' | pecl install -f memcached-3.2.0 \
      && docker-php-ext-enable memcached