how to install ZipArchive in the PHP Docker Container [duplicate] - php

I have a Dockerfile with a build command like this:
#install some base extensions
RUN apt-get install -y \
zlib1g-dev \
zip \
&& docker-php-ext-install zip
I get this warning from build output:
WARNING: Use of bundled libzip is deprecated and will be removed.
configure: WARNING: Some features such as encryption and bzip2 are not available.
configure: WARNING: Use system library and --with-libzip is
recommended.
What is the correct way to install the zip extension without these warnings?
My complete Dockerfile looks like:
FROM php:7.2-apache
RUN apt-get clean
RUN apt-get update
#install some basic tools
RUN apt-get install -y \
git \
tree \
vim \
wget \
subversion
#install some base extensions
RUN apt-get install -y \
zlib1g-dev \
zip \
&& docker-php-ext-install zip
#setup composer
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/ \
&& ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
WORKDIR /var/www/

It looks like PHP no longer bundles libzip. You need to install it. You install zlib1g-dev, but instead install libzip-dev. This installs zlib1g-dev as a dependency and allows the configure script to detect that libzip is installed.
For PHP < 7.3, you then need to
docker-php-ext-configure zip --with-libzip
before performing the installation with
docker-php-ext-install zip
as the last warning indicates.
In short: change the relevant part of your Dockerfile to
For PHP < 7.3
#install some base extensions
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip
For PHP >= 7.3
#install some base extensions
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install zip
I have verified that this builds as expected.
In case you are not using the Docker PHP base image, things may be much easier. For example, for Alpine the following Dockerfile will get you PHP 7 with the zip extension installed.
FROM alpine:latest
RUN apk update && apk upgrade
RUN apk add php7 php7-zip composer

In case you are using 7.4 this worked for me:
FROM php:7.4-fpm-alpine
RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql

I built a PHP container on Docker using php:7.2-fpm-alpine
FROM php:7.2-fpm-alpine
WORKDIR /var/www
RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip --with-libzip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql

Apparently the zip extension needs the libzip-dev package at runtime (not just build time). I originally added the apk add libzip-dev to a virtual package I installed along with gcc make postgresql-dev which I later removed to keep the image small.
This works:
RUN apk add openjdk11-jre-headless libzip-dev \ # libzip-dev not part of virtual package
&& apk add --no-cache --virtual \
.build-deps autoconf g++ make postgresql-dev \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip \
&& docker-php-ext-install pdo_pgsql bcmath \
&& pecl install redis-5.3.1 \
&& pecl install xdebug-beta \
&& docker-php-ext-enable redis opcache xdebug \
&& apk add libpq ca-certificates curl \
&& apk del .build-deps \
&& rm -rf /tmp/* \
&& rm -rf /var/cache/apk/*
This does not work:
RUN apk add openjdk11-jre-headless \
&& apk add --no-cache --virtual \
.build-deps autoconf g++ make postgresql-dev libzip-dev \ # libzip-dev part of virtual package
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip \
&& docker-php-ext-install pdo_pgsql bcmath \
&& pecl install redis-5.3.1 \
&& pecl install xdebug-beta \
&& docker-php-ext-enable redis opcache xdebug \
&& apk add libpq ca-certificates curl \
&& apk del .build-deps \
&& rm -rf /tmp/* \
&& rm -rf /var/cache/apk/*

In order to build a php/apache container you just have to first install libzip-dev library. At least using the docker image php:7.3-apache
FROM php:7.3-apache
MAINTAINER XXX
RUN apt-get update
RUN apt-get install -y libzip-dev
RUN docker-php-ext-install zip
Hope it helps

FROM php:8.1-fpm-alpine
# Install persistent dependencies
RUN set -eux; \
apk add --no-cache --update \
bash \
imagemagick \
ghostscript \
zip \
unzip \
nano \
libzip-dev \
libgomp
# Install the PHP extensions
RUN set -ex; \
apk add --no-cache --virtual .build-deps \
${PHPIZE_DEPS} \
freetype-dev \
icu-dev \
imagemagick-dev \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
zlib-dev \
; \

I built a PHP dockerfile using php:7.4-fpm-alpine
FROM php:7.4-fpm-alpine
# Apk install
RUN apk --no-cache update && apk --no-cache add bash git
RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql
# Install composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php && php -r "unlink('composer-setup.php');" && mv composer.phar /usr/local/bin/composer
# Symfony CLI
RUN wget https://get.symfony.com/cli/installer -O - | bash && mv /root/.symfony/bin/symfony /usr/local/bin/symfony
WORKDIR /var/www/html

this worked for me:
RUN docker-php-ext-configure zip --with-libzip

Related

How i can install snmp-module in php on Dokerfile

My problem: When i run command
docker build --no-cache -t php --progress=plain .
My container is building, but I get Error in my PHP-project:
Error Call to undefined function snmp2_real_walk()
Command install in Dockerfile is't work... I need help!!
My Dockerfile:
FROM php:7.4-apache
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN if command -v a2enmod >/dev/null 2>&1; then \
a2enmod rewrite headers \
;fi
RUN apt-get update
# Install tools required for build stage
RUN apt-get install -fyqq \
bash curl wget rsync ca-certificates openssl ssh git tzdata openntpd \
libxrender1 fontconfig libc6 \
mariadb-client gnupg binutils-gold autoconf \
g++ gcc gnupg libgcc1 linux-headers-amd64 make python
#RUN apt install -y libsnmp-dev
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
&& chmod 755 /usr/bin/composer
# Install additional PHP libraries
RUN docker-php-ext-install bcmath pdo_mysql
RUN \
apt-get update && \
apt-get install libldap2-dev -y && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-install ldap
# Install libraries for compiling GD, then build it
RUN apt-get update && apt-get install -y \
libfreetype6 \
libfreetype6-dev \
libjpeg62-turbo \
libjpeg62-turbo-dev \
libsqlite3-dev \
libssl-dev \
libpng-dev \
libpng16-16 \
libcurl3-dev \
libxml2-dev \
libonig-dev \
libsnmp-dev \
snmp \
&& docker-php-ext-install mysqli xmlrpc \
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install gd \
&& apt-get remove -fyqq libfreetype6-dev libpng-dev libjpeg62-turbo-dev
# -------------------- Installing PHP Extension: snmp --------------------
RUN docker-php-ext-configure snmp --with-snmp \
# Installation
&& docker-php-ext-install -j$(getconf _NPROCESSORS_ONLN) snmp \
&& true
RUN sed -i 's/;extension=snmp/extension=snmp/' php.ini-production
# Add ZIP archives support
RUN apt-get install -fyqq zip libzip-dev \
&& docker-php-ext-install zip \
&& apt-get remove -fyqq libzip-dev
# Install xdebug
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
# Enable XDebug
ADD xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
WORKDIR /app
I've tried a lot of options. Editing the
php.ini-production
file did not lead to the expected result. At the same time, the php.ini file also does not exist, but the command is present...

Does not work iconv with Docker FPM Alpine

That's my dockerfile setup. When I use Laravel Dompdf the error will show "iconv(): Wrong charset, conversion from utf-8' to us-ascii//TRANSLIT' is not allowed"
And I have been checked the PHP ini, the iconv has been enabled. In my docker file also added the iconv installation command. It still doesn't work. Any solutions for my docker setting?
FROM php:7.3.33-fpm-alpine
# Fix: iconv(): Wrong charset, conversion from UTF-8 to UTF-8//IGNORE is not allowed in Command line code on line 1
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
# Install php extensions
RUN apk update \
&& apk add --no-cache libzip-dev libmcrypt libmcrypt-dev zlib-dev \
&& docker-php-ext-install exif zip bcmath mysqli pdo pdo_mysql ctype json
# Install GD extensions
RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \
docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ && \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
docker-php-ext-install -j${NPROC} gd && \
apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
RUN apk --no-cache update \
&& apk --no-cache add make bash g++ zlib-dev libpng-dev \
&& rm -fr /var/cache/apk/*
# Install npm for Laravel Mix
RUN apk add npm
RUN apk add nodejs-lts --update
RUN npm install -g npm
WORKDIR /application
EXPOSE 9000
# Start services
CMD ["php-fpm"]
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.12/community/ --allow-untrusted gnu-libiconv=1.15-r2
that's work to me

Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning

I have a Dockerfile with a build command like this:
#install some base extensions
RUN apt-get install -y \
zlib1g-dev \
zip \
&& docker-php-ext-install zip
I get this warning from build output:
WARNING: Use of bundled libzip is deprecated and will be removed.
configure: WARNING: Some features such as encryption and bzip2 are not available.
configure: WARNING: Use system library and --with-libzip is
recommended.
What is the correct way to install the zip extension without these warnings?
My complete Dockerfile looks like:
FROM php:7.2-apache
RUN apt-get clean
RUN apt-get update
#install some basic tools
RUN apt-get install -y \
git \
tree \
vim \
wget \
subversion
#install some base extensions
RUN apt-get install -y \
zlib1g-dev \
zip \
&& docker-php-ext-install zip
#setup composer
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/ \
&& ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
WORKDIR /var/www/
It looks like PHP no longer bundles libzip. You need to install it. You install zlib1g-dev, but instead install libzip-dev. This installs zlib1g-dev as a dependency and allows the configure script to detect that libzip is installed.
For PHP < 7.3, you then need to
docker-php-ext-configure zip --with-libzip
before performing the installation with
docker-php-ext-install zip
as the last warning indicates.
In short: change the relevant part of your Dockerfile to
For PHP < 7.3
#install some base extensions
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip
For PHP >= 7.3
#install some base extensions
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install zip
I have verified that this builds as expected.
In case you are not using the Docker PHP base image, things may be much easier. For example, for Alpine the following Dockerfile will get you PHP 7 with the zip extension installed.
FROM alpine:latest
RUN apk update && apk upgrade
RUN apk add php7 php7-zip composer
In case you are using 7.4 this worked for me:
FROM php:7.4-fpm-alpine
RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql
I built a PHP container on Docker using php:7.2-fpm-alpine
FROM php:7.2-fpm-alpine
WORKDIR /var/www
RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip --with-libzip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql
Apparently the zip extension needs the libzip-dev package at runtime (not just build time). I originally added the apk add libzip-dev to a virtual package I installed along with gcc make postgresql-dev which I later removed to keep the image small.
This works:
RUN apk add openjdk11-jre-headless libzip-dev \ # libzip-dev not part of virtual package
&& apk add --no-cache --virtual \
.build-deps autoconf g++ make postgresql-dev \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip \
&& docker-php-ext-install pdo_pgsql bcmath \
&& pecl install redis-5.3.1 \
&& pecl install xdebug-beta \
&& docker-php-ext-enable redis opcache xdebug \
&& apk add libpq ca-certificates curl \
&& apk del .build-deps \
&& rm -rf /tmp/* \
&& rm -rf /var/cache/apk/*
This does not work:
RUN apk add openjdk11-jre-headless \
&& apk add --no-cache --virtual \
.build-deps autoconf g++ make postgresql-dev libzip-dev \ # libzip-dev part of virtual package
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip \
&& docker-php-ext-install pdo_pgsql bcmath \
&& pecl install redis-5.3.1 \
&& pecl install xdebug-beta \
&& docker-php-ext-enable redis opcache xdebug \
&& apk add libpq ca-certificates curl \
&& apk del .build-deps \
&& rm -rf /tmp/* \
&& rm -rf /var/cache/apk/*
In order to build a php/apache container you just have to first install libzip-dev library. At least using the docker image php:7.3-apache
FROM php:7.3-apache
MAINTAINER XXX
RUN apt-get update
RUN apt-get install -y libzip-dev
RUN docker-php-ext-install zip
Hope it helps
FROM php:8.1-fpm-alpine
# Install persistent dependencies
RUN set -eux; \
apk add --no-cache --update \
bash \
imagemagick \
ghostscript \
zip \
unzip \
nano \
libzip-dev \
libgomp
# Install the PHP extensions
RUN set -ex; \
apk add --no-cache --virtual .build-deps \
${PHPIZE_DEPS} \
freetype-dev \
icu-dev \
imagemagick-dev \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
zlib-dev \
; \
I built a PHP dockerfile using php:7.4-fpm-alpine
FROM php:7.4-fpm-alpine
# Apk install
RUN apk --no-cache update && apk --no-cache add bash git
RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql
# Install composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php && php -r "unlink('composer-setup.php');" && mv composer.phar /usr/local/bin/composer
# Symfony CLI
RUN wget https://get.symfony.com/cli/installer -O - | bash && mv /root/.symfony/bin/symfony /usr/local/bin/symfony
WORKDIR /var/www/html
this worked for me:
RUN docker-php-ext-configure zip --with-libzip

Troubles with Docker + PHP7 + GD resulting in "Call to undefined function imagecreatefromjpeg()"

I'm having troubles when trying to create an image using imagecreatefromjpeg using this Dockerfile to generate the container:
FROM php:7.1-apache
RUN apt-get update && \
apt-get install -y -qq git \
libjpeg62-turbo-dev \
apt-transport-https \
libfreetype6-dev \
libmcrypt-dev \
libpng12-dev \
libssl-dev \
zip unzip \
nodejs \
npm \
wget \
vim
RUN pecl install redis && docker-php-ext-enable redis
RUN docker-php-ext-install -j$(nproc) iconv mcrypt zip pdo pdo_mysql gd bcmath
COPY ./containers/yii.conf /etc/apache2/sites-available/000-default.conf
RUN for mod in rewrite headers; do a2enmod $mod; done && service apache2 restart
WORKDIR /var/www/html/
GD was correctly installed (libjpeg too - both appearing in php -i and phpinfo()) but imagecreatefromjpeg does not works and I don't know why.
I also ran apt install libjpeg-dev libpng-dev libfreetype6-dev trying to ~force~ reinstallation (or reconfiguration) but seems doesn't succeded (yes, I also restart the container).
root#e8db647c96c4:/var/www/html# php -i | grep -i GD
/usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
gd.jpeg_ignore_warning => 1 => 1
root#e8db647c96c4:/var/www/html#
root#e8db647c96c4:/var/www/html# docker-php-ext-enable gd
warning: gd (gd.so) is already loaded!
root#e8db647c96c4:/var/www/html#
I've tried apt install libgd2-xpm-dev* and apparently it doesn't solves the problem.
Solved
I was missing to put
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
into my Dockerfile.
Full revised Dockerfile:
FROM php:7.1-apache
RUN apt-get update && \
apt-get install -y -qq git \
libjpeg62-turbo-dev \
apt-transport-https \
libfreetype6-dev \
libmcrypt-dev \
libpng12-dev \
libssl-dev \
zip unzip \
nodejs \
npm \
wget \
vim
RUN pecl install redis && docker-php-ext-enable redis
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) iconv mcrypt zip pdo pdo_mysql gd bcmath
COPY ./containers/yii.conf /etc/apache2/sites-available/000-default.conf
RUN for mod in rewrite headers; do a2enmod $mod; done && service apache2 restart
WORKDIR /var/www/html/
PHP 7.4 (Alpine)
If anybody is struggling to enable JPEG support in GD with PHP 7.4, here's what I had to do in order to be able to use imagecreatefromjpeg() function.
My example is based on Alpine 3.10, if you're using other distribution adjust it to your needs.
First install dependencies, in my case beside JPEG I need support for PNG files.
apk add jpeg-dev libpng-dev
After that we can run docker-php-ext-configure command to configure our gd with JPEG support. Notice that flag --with-jpeg-dir was changed to --with-jpeg and we don't need to provide flag to enable PNG. More you can read in PHP 7.4 Changelog in GD section.
docker-php-ext-configure gd --with-jpeg
Directly after that let's run docker-php-ext-install to install GD itself.
docker-php-ext-install -j$(nproc) gd
FULL EXAMPLE
FROM php:7.4-fpm-alpine3.10
RUN apk add jpeg-dev libpng-dev \
&& docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
For PHP 5.6
FROM php:5.6-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev libjpeg62-turbo-dev \
libgd-dev libpng12-dev
RUN docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
If still not working, can re-install the container.
docker rm <container id>
docker-compose build --pull
docker-compose up
Updated Version PHP 7.4 + Apache:
Dockerfile
FROM php:7.4-apache
RUN apt-get update -y && apt-get install -y sendmail libpng-dev libfreetype6-dev libjpeg62-turbo-dev libgd-dev libpng-dev
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-configure gd \
--with-freetype=/usr/include/ \
--with-jpeg=/usr/include/
RUN docker-php-ext-install gd
...
Add these Commands
docker-php-ext-configure gd --with-freetype --with-jpeg
docker-php-ext-install -j$(nproc) gd
Working full Dockerfile:
FROM php:7.4-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /src/
# Set working directory
WORKDIR /src
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg-dev \
libwebp-dev \
libxpm-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install pdo_mysql exif pcntl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install --prefer-source --no-interaction
COPY . /src
RUN chmod 777 -R /src/storage
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]

How can I install the php memcached extension on Docker's PHP7 Alpine image?

The official php7 docker image has the following example:
FROM php:7.0-fpm
RUN apt-get update && apt-get install -y libmemcached-dev \
&& pecl install memcached \
&& docker-php-ext-enable memcached
I'm trying to use FROM php:7.0-fpm-alpine:
RUN apk add --update --no-cache libmemcached-dev
RUN pecl install memcached && docker-php-ext-enable memcached
PECL gives this error:
pecl/memcached requires PHP (version >= 5.2.0, version <= 6.0.0,
excluded versions: 6.0.0), installed version is 7.0.13
How can I install the memcached php extension on alpine?
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 git
RUN 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-alpine
ENV MEMCACHED_DEPS zlib-dev libmemcached-dev cyrus-sasl-dev
RUN apk add --no-cache --update libmemcached-libs zlib
RUN 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 zlib
RUN 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
This works for me on Debian 11
FROM php:7.4.28-apache
RUN apt-get install -y libz-dev libmemcached-dev && \
apt-get install -y memcached libmemcached-tools && \
pecl install memcached && \
docker-php-ext-enable memcached
And you can start the daemon using something like this:
/etc/init.d/memcached start

Categories