docker-library / php

Docker Official Image packaging for PHP
https://php.net
MIT License
3.83k stars 2.01k forks source link

Memcached support #132

Closed polds closed 9 years ago

polds commented 9 years ago

Wondering if anyone has gotten memcached (not memcache) to work? Trying to build in php:5.5.29-apache to get the php memcached module installed. I have tried the following to no avail. Any help is greatly appreciated.

Dockerfile 1

FROM php:5.5.29-apache

RUN apt-get update \
  && apt-get install -y php5-memcached

CMD ["apache2", "-DFOREGROUND"]

Notes:

The following extra packages will be installed:
  libmemcached11 libmemcachedutil2 libperl4-corelibs-perl lsof php5-common
  psmisc ucf
Suggested packages:
  php5-user-cache
The following NEW packages will be installed:
  libmemcached11 libmemcachedutil2 libperl4-corelibs-perl lsof php5-common
  php5-memcached psmisc ucf
...
Creating config file /etc/php5/mods-available/pdo.ini with new version
Creating config file /etc/php5/mods-available/opcache.ini with new version

Dockerfile 2

FROM php:5.5.29-apache

RUN apt-get update \
  && apt-get install -y php5-memcached \
  && apt-get install -y build-essential memcached php-pear \
  && yes | pecl install memcached

CMD ["apache2", "-DFOREGROUND"]

Notes:

checking for ZLIB... yes, shared
checking for zlib location... configure: error: memcached support requires ZLIB. Use --with-zlib-dir=<DIR> to specify the prefix where ZLIB headers and library are located
ERROR: `/tmp/pear/temp/memcached/configure --with-libmemcached-dir=y' failed

Dockerfile 3

FROM php:5.5.29-apache

RUN apt-get update \
  && apt-get install -y php5-dev php5-memcached \
  && apt-get install -y memcached

CMD ["apache2", "-DFOREGROUND"]

Notes:

The following extra packages will be installed:
  automake autopoint autotools-dev bsdmainutils build-essential bzip2
  debhelper dh-php5 dpkg-dev fakeroot gettext gettext-base groff-base
  intltool-debian libalgorithm-diff-perl libalgorithm-diff-xs-perl
  libalgorithm-merge-perl libasprintf-dev libasprintf0c2 libbsd0 libcroco3
  libdpkg-perl libedit2 libfakeroot libfile-fcntllock-perl libgettextpo-dev
  libgettextpo0 libjson-c2 libltdl-dev libltdl7 libmail-sendmail-perl
  libmemcached11 libmemcachedutil2 libonig2 libpcre3-dev libpcrecpp0
  libperl4-corelibs-perl libpipeline1 libqdbm14 libssl-dev libssl-doc
  libsys-hostname-long-perl libtimedate-perl libtool libunistring0 lsof man-db
  patch php-pear php5-cli php5-common php5-json php5-readline pkg-php-tools
  po-debconf psmisc shtool ucf xz-utils zlib1g-dev
Suggested packages:
  wamerican wordlist whois vacation bzip2-doc dh-make debian-keyring
  gettext-doc groff libtool-doc automaken gfortran fortran95-compiler gcj-jdk
  less www-browser ed diffutils-doc php5-user-cache libmail-box-perl
The following NEW packages will be installed:
  automake autopoint autotools-dev bsdmainutils build-essential bzip2
  debhelper dh-php5 dpkg-dev fakeroot gettext gettext-base groff-base
  intltool-debian libalgorithm-diff-perl libalgorithm-diff-xs-perl
  libalgorithm-merge-perl libasprintf-dev libasprintf0c2 libbsd0 libcroco3
  libdpkg-perl libedit2 libfakeroot libfile-fcntllock-perl libgettextpo-dev
  libgettextpo0 libjson-c2 libltdl-dev libltdl7 libmail-sendmail-perl
  libmemcached11 libmemcachedutil2 libonig2 libpcre3-dev libpcrecpp0
  libperl4-corelibs-perl libpipeline1 libqdbm14 libssl-dev libssl-doc
  libsys-hostname-long-perl libtimedate-perl libtool libunistring0 lsof man-db
  patch php-pear php5-cli php5-common php5-dev php5-json php5-memcached
  php5-readline pkg-php-tools po-debconf psmisc shtool ucf xz-utils zlib1g-dev

...

The following extra packages will be installed:
  init-system-helpers libevent-2.0-5
Suggested packages:
  libcache-memcached-perl libmemcached libanyevent-perl libyaml-perl
  libterm-readkey-perl
The following NEW packages will be installed:
  init-system-helpers libevent-2.0-5 memcached
md5 commented 9 years ago

@polds I think you want to use "Dockerfile 2", but you need to install libz-dev to make configure happy.

md5 commented 9 years ago

Actually, nevermind... I thought you were using docker-php-ext-install :confused:

You need something like this:

FROM php:5.5.29-apache
RUN apt-get update && apt-get install -y libz-dev libmemcached-dev
RUN pecl install memcached
polds commented 9 years ago

@md5 thank you that was indeed it with the following modification (for future readers):

FROM php:5.5.29-apache
RUN apt-get update && apt-get install -y libz-dev libmemcached-dev
RUN pecl install memcached
RUN echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini
md5 commented 9 years ago

Thanks @polds.

That reminds me that @helderco once mentioned creating a docker-php-pecl-install script: https://github.com/docker-library/php/issues/115#issuecomment-120720217

hairmare commented 9 years ago

The smallest layer for the pecl install is probably the following:

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
polds commented 9 years ago

^ That worked as well.

md5 commented 9 years ago

Thanks @hairmare I was being lazy since I don't tend to be as aggressive with the sizes of "normal" images.

I think you'll also want a rm -rf /var/lib/apt/lists/* in there as well since apt-get clean doesn't clean as much as it could.

roelvanduijnhoven commented 8 years ago

I failed to get memcached to work on PHP7. Finally managed to do so using the following lines, using the php7 branch and building from source:

# Memcached
RUN apt-get install -y libmemcached-dev \
 && cd /tmp \
 && git clone -b php7 https://github.com/php-memcached-dev/php-memcached.git \
 && cd php-memcached \
 && phpize \
 && ./configure \
 && make \
 && echo "extension=/tmp/php-memcached/modules/memcached.so" > /usr/local/etc/php/conf.d/memcached.ini

Is there any better way?

paolomainardi commented 8 years ago

@roelvanduijnhoven for PHP7 ì'm doing this:

  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 
roelvanduijnhoven commented 8 years ago

Thanks @paolomainardi, looks a lot easier. I realise now how the bundled docker-php-ext.. scripts work.

paolomainardi commented 8 years ago

@roelvanduijnhoven you're welcome

skyred commented 8 years ago

Thank you all. I further shortened https://github.com/docker-library/php/issues/132#issuecomment-170924782 a little bit. Now, I am using this config in my image for Drupal https://github.com/INsReady/php-fpm-for-cms/blob/master/7.0/Dockerfile#L11

vitalyzhakov commented 8 years ago

With last version php:7.0-fpm stop working

Cloning into '/usr/src/php/ext/memcached'...
usage: /usr/local/bin/docker-php-ext-configure ext-name [configure flags]
   ie: /usr/local/bin/docker-php-ext-configure gd --with-jpeg-dir=/usr/local/something
Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mcrypt mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip
``
yosifkit commented 8 years ago

@vitalyzhakov, I think that is related to #266.

roelvanduijnhoven commented 8 years ago

Did anyone manage to fix this problem? I am reading through #266 but have no clue if and how I should solve this..

vitalyzhakov commented 8 years ago

@roelvanduijnhoven ,

This code works for me under php 7.0.8-fpm

# install memcached
    && apt-get -y install libmemcached11 libmemcachedutil2 libmemcached-dev \
    && git clone --branch php7 https://github.com/php-memcached-dev/php-memcached \
    && cd php-memcached \
    && phpize \
    && ./configure \
    && make \
    && echo "extension=/var/www/html/php-memcached/modules/memcached.so" > /usr/local/etc/php/conf.d/memcached.ini 
roelvanduijnhoven commented 8 years ago

Thanks! :heart:

rasteiner commented 8 years ago

This may be obvious, but for someone (like me) it's not.

Notice that the above snippet puts the memcached library into /var/www/html/. When you create a volume from a host directory and mount that into /var/www/html, docker "overwrites" that path and your module "disappears".

So if you want to mount a volume into /var/www/html, change the snippet to clone the repo into another directory and adjust the corresponding line that creates the php config file.

Something like this works for me:

RUN apt-get -y install libmemcached11 libmemcachedutil2 libmemcached-dev \
    && cd /usr/local/share \
    && git clone --branch php7 https://github.com/php-memcached-dev/php-memcached \
    && cd php-memcached \
    && phpize \
    && ./configure \
    && make \
    && echo "extension=/usr/local/share/php-memcached/modules/memcached.so" > /usr/local/etc/php/conf.d/memcached.ini
c0deright commented 8 years ago

Please do it the right way: use the docker-php-* scripts and cleanup afterwards.

The best practice should look something like this:

FROM php:7.0-fpm

RUN apt-get update \
        && buildDeps=" \
                git \
                libmemcached-dev \
                zlib1g-dev \
        " \
        && doNotUninstall=" \
                libmemcached11 \
                libmemcachedutil2 \
        " \
        && apt-get install -y $buildDeps --no-install-recommends \
        && rm -r /var/lib/apt/lists/* \
        \
        && docker-php-source extract \
        && git clone --branch php7 https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached/ \
        && docker-php-ext-install memcached \
        \
        && docker-php-source delete \
        && apt-mark manual $doNotUninstall \
        && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $buildDeps

This way you use docker-php-source, don't have to create an ini file, call phpize and make yourself and most important this way you remove not needed -dev packages and all their dependencies (except for runtime dependencies in $doNotUninstall) to save disk-space.

bscheshir commented 8 years ago

@adminblogger nice! Thx!

If your favor... Tell me pls... Where can i find runtime dependencies for another extensional? I can mark to delete git, zlib1g-dev, but someone once? Using on install

FROM php:7.0.11-fpm
RUN apt-get update && apt-get install -y \
        git \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
        zlib1g-dev \
        libicu-dev \
        libpq-dev \
        libmagickwand-dev \
    && apt-get clean \
    && docker-php-ext-install -j$(nproc) pdo_mysql pdo_pgsql \
    && docker-php-ext-configure intl \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) intl gd \
    && pecl install imagick \
    && docker-php-ext-enable imagick
jordanlgraham commented 7 years ago

For anyone who finds this because their Dockerfile has begun to fail while trying "pecl install memcached" (with the error "pecl/memcached requires PHP (version >= 7.0.0), installed version is [5.6.something]", on 02/08/17 the pecl memcached package version 3.0 was released, requiring php 7.0 or higher.

To continue using memcached with php 5.6.x, update your Dockerfile to use version 2.2.0 of the memcached package:

pecl install memcached-2.2.0

instead of

pecl install memcached

The relevant section of my Dockerfile, as a result, is:

RUN apt-get -y install libz-dev libmemcached-dev libmemcached11 libmemcachedutil2 build-essential \ && pecl install memcached-2.2.0 \ && 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