Php: memcache not detected

Created on 7 Jun 2018  路  5Comments  路  Source: docker-library/php

I'm trying to install the memcache library for php 5.6, however when I check with php -m the installation is not reflected:

# docker-compose.yml
...
version: '3'
...
php:
    ...
    build: "./config/php"
    ...
    volumes:
      - "./config/php/conf.d:/usr/local/etc/php/conf.d"
      - "./config/php/extensions/memcache.so:/usr/local/lib/php/extensions/no-debug-non-zts-20131226/memcache.so"
      - "./config/apache/sites-available/000-default.conf:/etc/apache2/sites-available/000-default.conf"
      - "./config/apache/logs/access.log:/var/log/apache2/access.log"
      - "./config/apache/logs/error.log:/var/log/apache2/error.log"
      - "./src/front-php:/var/www/html"
...
# Dockerfile

FROM php:5.6-apache
; conf.d/memcache.ini

extension=memcache.so

Enviroment:

Docker version 18.03.1-ce, build 9ee9f40
docker-compose version 1.21.1, build 5a3f1a3

question

Most helpful comment

Looks like you just need to add && docker-php-ext-enable memcache to the pecl install line from Tianon and the module shows up.

All 5 comments

I'm not well versed in php, but if by library you mean extension; as would be reflected in php -m then the documentation for this image has relevant information.
There is also an issue outlining the exact steps for installing memcache on php:5.6-apache https://github.com/docker-library/php/issues/575 if that is what you're wanting

So the Dockerfile

FROM php:5.6-apache
RUN apt-get update \
&& apt-get install -y \
libz-dev libmemcached-dev libmemcached11 libmemcachedutil2 build-essential memcached \
&& 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
$ docker run --rm -d --name php_test php_test
$ docker exec -it php_test bash
root@f0be80e294d7:/var/www/html# php -m | grep memcache
memcached
root@f0be80e294d7:/var/www/html# php -i | grep memcache
Additional .ini files parsed => /usr/local/etc/php/conf.d/memcached.ini
memcached
memcached support => enabled
. . .

Thanks for your comments @wglambert, the problem is that I need memcache and not memcached, memcache is an older version, this is the main problem that I could not use my project in Docker.

Using the following, I'm able to compile memcache successfully (from https://pecl.php.net/package/memcache):

FROM php:5.6-apache
RUN apt-get update && apt-get install -y --no-install-recommends zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN pecl install memcache-2.2.7

(both with 2.2.7 and 3.0.8)

However, it still doesn't show up in php -m and attempts to use new Memcache from PHP fail with Fatal error: Class 'Memcache' not found in php shell code on line 1. Looking at the release date on that code, the latest _beta_ release of the memcache module was 2013, latest stable in 2012 (which references PHP 5.4:exclamation:), so I imagine it probably simply doesn't support the more recent PHP 5.6 (and you'll have to acquire/build something older and unsupported like 5.4 if this is necessary for your project).

Looks like you just need to add && docker-php-ext-enable memcache to the pecl install line from Tianon and the module shows up.

Thanks @tianon and @yosifkit that works for me.

Was this page helpful?
0 / 5 - 0 ratings