Uncaught Error: Class 'Memcached' not found in docker container

早过忘川 提交于 2020-12-16 06:42:12

问题


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('https://getcomposer.org/installer', '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

<?php
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?


回答1:


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 extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini

after the FROM php:7.1.2-apache




回答2:


You might be missing the memcached package.

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



来源:https://stackoverflow.com/questions/46826441/uncaught-error-class-memcached-not-found-in-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!