2

I have an app with Docker, and I am trying to install memcached with php7-fpm.

According to official docker documentation I have in my Dockerfile:

# PHP Version
FROM php:7.0-fpm

...

# Install Memcached
RUN apt-get install -y libmemcached-dev && \
pecl install memcached && \
docker-php-ext-enable memcached

But I got this error:

pecl/memcached requires PHP (version >= 5.2.0, version <= 6.0.0, excluded versions: 6.0.0), installed version is 7.0.9

I don't want to switch to PHP 5.6. Any ideas?

halfer
  • 19,824
  • 17
  • 99
  • 186
Mauro
  • 189
  • 2
  • 14

3 Answers3

8

We build the memcache extension from scratch when building our php7 container. Maybe our approached helps you or points you to the right direction. The documentation in the Dockerhub really seems to be faulty, tried pecl and it didn't work here either.

So this is how it looks in our Dockerfile:

RUN apt-get update && apt-get install -y 
        libmemcached11 \
        libmemcachedutil2 \
        libmemcached-dev \
        libz-dev \
        git \
    && cd /root \
    && git clone -b php7 https://github.com/php-memcached-dev/php-memcached \
    && cd php-memcached \
    && phpize \
    && ./configure \
    && make \
    && make install \
    && cd .. \
    && rm -rf  php-memcached \
    && echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini \
    && apt-get remove -y build-essential libmemcached-dev libz-dev \
    && apt-get remove -y libmemcached-dev libz-dev \
    && apt-get autoremove -y \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean
Sibren
  • 1,068
  • 11
  • 11
kgorskowski
  • 745
  • 5
  • 12
  • /root/php-memcached/php_memcached.c: In function 'zim_Memcached___construct': /root/php-memcached/php_memcached.c:1282:20: error: lvalue required as left operand of assignment GC_REFCOUNT(&le) = 1; ^ make: *** [Makefile:192: php_memcached.lo] Error 1 – Mcile Apr 05 '21 at 11:48
2

It seems that the memcached is incompatible with php7 and need another way to install it.

After a quick lock at Laradock repo I solved in this manner, I post the code:

# PHP Version
FROM php:7.0-fpm

# Install the PHP extensions we need
RUN apt-get update && \
apt-get install -y --no-install-recommends \
    curl \
    libmemcached-dev \
    libz-dev \
    libpq-dev \
    libjpeg-dev \
    libpng12-dev \
    libfreetype6-dev \
    libicu-dev \
    libssl-dev \
    libmcrypt-dev && \
    docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr && \
    docker-php-ext-install gd mysqli opcache intl

    .....

 # Install Memcached
RUN curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-   dev/php-memcached/archive/php7.tar.gz" && \
mkdir -p memcached && \
tar -C memcached -zxvf /tmp/memcached.tar.gz --strip 1 && \
( \
    cd memcached && \
    phpize && \
    ./configure && \
    make -j$(nproc) && \
    make install \
) && \
rm -r memcached && \
rm /tmp/memcached.tar.gz && \
docker-php-ext-enable memcached
halfer
  • 19,824
  • 17
  • 99
  • 186
Mauro
  • 189
  • 2
  • 14
0

one more solution

FROM php:7.2-fpm
# ...
# INSTALL memcached
RUN apt-get upgrade -y
RUN apt-get install -y memcached
RUN apt-get install -y libmemcached-dev zlib1g-dev libicu-dev
RUN git clone -b php7 https://github.com/php-memcached-dev/php-memcached 
/usr/src/php/ext/memcached \
&& docker-php-ext-configure /usr/src/php/ext/memcached \
    --disable-memcached-sasl \
&& docker-php-ext-install /usr/src/php/ext/memcached \
&& rm -rf /usr/src/php/ext/memcached
haiflive
  • 1,411
  • 13
  • 13