How can I install the php memcached extension on Docker's PHP7 Alpine image?
Currently the php-memcached-dev:php7 branch contains the source for this extension.
To install it you can still use the docker-php-ext-*
commands but you need to checkout the source yourself.
Base Installation
Assuming everything required to install the extension is already installed you can do:
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
This block will clone the repository, configure and install the extension then clean up after it self.
Pre-requisites
It is most likely that you need to install to packages to build the extension, we can add and remove them by doing:
ENV MEMCACHED_DEPS zlib-dev libmemcached-dev cyrus-sasl-dev gitRUN set -xe \ && apk add --no-cache libmemcached-libs zlib \ && apk add --no-cache \ --virtual .memcached-deps \ $MEMCACHED_DEPS \ && 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 \ && apk del .memcached-deps
Update 17 May 2017
memcached
has been added to the official pecl libraries for php7 now (v3 -> php7/7.1, v2 -> php5)
This makes installation a bit different
FROM php:7.0-alpineENV MEMCACHED_DEPS zlib-dev libmemcached-dev cyrus-sasl-devRUN apk add --no-cache --update libmemcached-libs zlibRUN set -xe \ && apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS \ && apk add --no-cache --update --virtual .memcached-deps $MEMCACHED_DEPS \ && pecl install memcached \ && echo "extension=memcached.so" > /usr/local/etc/php/conf.d/20_memcached.ini \ && rm -rf /usr/share/php7 \ && rm -rf /tmp/* \ && apk del .memcached-deps .phpize-deps
Try it.
FROM php:7.2.10-fpm-alpine3.7# Install PHP Extensions (igbinary & memcached)RUN apk add --no-cache --update libmemcached-libs zlibRUN set -xe && \ cd /tmp/ && \ apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS && \ apk add --no-cache --update --virtual .memcached-deps zlib-dev libmemcached-dev cyrus-sasl-dev && \# Install igbinary (memcached's deps) pecl install igbinary && \# Install memcached ( \ pecl install --nobuild memcached && \ cd "$(pecl config-get temp_dir)/memcached" && \ phpize && \ ./configure --enable-memcached-igbinary && \ make -j$(nproc) && \ make install && \ cd /tmp/ \ ) && \# Enable PHP extensions docker-php-ext-enable igbinary memcached && \ rm -rf /tmp/* && \ apk del .memcached-deps .phpize-deps