2017-10-19 09:11
浏览 76


I am trying to deploy php7 slim application into docker. This is how my Dockerfile looks like:

FROM php:7.1.2-apache

RUN php -r "copy('', 'composer-setup.php');" && \
    php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
    php composer-setup.php && \
    php -r "unlink('composer-setup.php');" && \
    mv composer.phar /usr/local/bin/composer

ADD sourcecode  /var/www/html

RUN composer install
RUN sed -i 's/DocumentRoot.*$/DocumentRoot \/var\/www\/html\/src/' /etc/apache2/sites-enabled/000-default.conf

This is snippet of code where Memcached initialized

global $config;

$cache_settings = $config['settings']['memcached'];

$memcached = new Memcached;
$memcached->addServer($cache_settings['host'], $cache_settings['port']) or die ("CANNOT connect to memcached");

I also have Memcached and Mysql containers are running. All staff is launching by docker-compose file. But when I am requesting for a page of my app, I get this error:

Uncaught Error: Class 'Memcached' not found in ...

How can I fix this issue?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dopa53272
    dopa53272 2017-10-19 11:50

    Try to add :

    RUN apt-get update && apt-get install -y libz-dev libmemcached-dev && rm -r /var/lib/apt/lists/* RUN pecl install memcached RUN echo >> /usr/local/etc/php/conf.d/memcached.ini

    after the FROM php:7.1.2-apache

    点赞 评论
  • dpy33121
    dpy33121 2017-10-19 10:03

    You might be missing the memcached package.

    You can install it as follows: apt-get install memcached

    点赞 评论