Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malitov/def226c19dd40df369e9360b40f6bffb to your computer and use it in GitHub Desktop.
Save malitov/def226c19dd40df369e9360b40f6bffb to your computer and use it in GitHub Desktop.
Install PHP Memcache in docker php
PHP 5.6:
RUN apt-get update \
&& apt-get install -y libmemcached11 libmemcachedutil2 build-essential libmemcached-dev libz-dev \
&& pecl install 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 autoremove -y \
&& apt-get clean \
&& rm -rf /tmp/pear
PHP 7:
git clone https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached \
&& cd /usr/src/php/ext/memcached && git checkout -b php7 origin/php7 \
&& docker-php-ext-configure memcached \
&& docker-php-ext-install memcached
@TiagoGouvea
Copy link

It gives " configure: error: memcached support requires ZLIB. Use --with-zlib-dir=

to specify the prefix where ZLIB headers and library are located"

@treboryug
Copy link

On PHP 7, you should then install ZLIB first before installing MEMCACHED

RUN apt-get update && apt-get install --no-install-recommends -y
libzip-dev
zlibc
zlib1g
&& docker-php-ext-configure zip --with-libzip
&& docker-php-ext-install zip

retry installing memcached

@oviniciusfeitosa
Copy link

oviniciusfeitosa commented Oct 6, 2020

Simplified way

RUN apt-get update && apt-get install --no-install-recommends -y memcached libmemcached-tools libzip-dev zlibc zlib1g \
  && docker-php-ext-configure zip --with-libzip \
  && docker-php-ext-install zip \
  && git clone https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached \
  && cd /usr/src/php/ext/memcached && git checkout -b php7 origin/php7 \
  && docker-php-ext-configure memcached \
  && docker-php-ext-install memcached

@chouchensamih
Copy link

Thank you vinnyfs89 this worked for me after adding libmemcached-dev and git in debian 9 docker image

apt-get update \
&& apt-get install --no-install-recommends -y memcached libmemcached-tools libzip-dev zlibc zlib1g  git  libmemcached-dev \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
&& git clone https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached && cd /usr/src/php/ext/memcached \
&& git checkout -b php7 origin/php7 \
&& docker-php-ext-configure memcached   && docker-php-ext-install memcached 

@ivenms
Copy link

ivenms commented May 27, 2021

Simplified way

RUN apt-get update && apt-get install --no-install-recommends -y memcached libmemcached-tools libzip-dev zlibc zlib1g \
  && docker-php-ext-configure zip --with-libzip \
  && docker-php-ext-install zip \
  && git clone https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached \
  && cd /usr/src/php/ext/memcached && git checkout -b php7 origin/php7 \
  && docker-php-ext-configure memcached \
  && docker-php-ext-install memcached

I m getting the following error while using the same commands:
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

EDIT:
I managed to resolve the issue by the solution given on:
php-memcached-dev/php-memcached#408

@paulzhn
Copy link

paulzhn commented Nov 5, 2021

you don't need to switch the branch to php7 now, for the master branch has supported it. Or you can just download the latest release, unzip and install as the same.

@StEvUgnIn
Copy link

#13 6.136  cc -I/usr/local/include/php -I. -I/usr/src/php/ext/memcached -DPHP_AT
OM_INC -I/usr/src/php/ext/memcached/include -I/usr/src/php/ext/memcached/main -I
/usr/src/php/ext/memcached -I/usr/local/include/php -I/usr/local/include/php/mai
n -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/inclu
de/php/ext -I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic
-fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -fstack-pro
tector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/
local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I
/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/ph
p/ext/date/lib -c /usr/src/php/ext/memcached/php_memcached.c  -fPIC -DPIC -o .li
bs/php_memcached.o
#13 6.355 /usr/src/php/ext/memcached/php_memcached.c: In function 'zim_Memcached
___construct':
#13 6.355 /usr/src/php/ext/memcached/php_memcached.c:1282:20: error: lvalue requ
ired as left operand of assignment
#13 6.355  1282 |   GC_REFCOUNT(&le) = 1;
#13 6.355       |                    ^
#13 6.395 make: *** [Makefile:192: php_memcached.lo] Error 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment