我正在尝试使用Docker设置现有项目。该项目位于codeigniter中,并使用memcached作为驱动程序来设置会话。
我用php:7.1.8-apache
创建了一个Docker环境,并安装了所有必要的软件包。
我现在在页面上收到此错误
Warning Message: session_start(): Failed to read session data: user (path: localhost:11211:128)
我在互联网上进行了很多搜索,并尝试了很多方法,但没有任何效果。
我在application/libraries/Session/drivers/Session_memcached_driver.php
中有一个文件
这是从中生成错误的代码段,但是我不确定它到底是什么。
public function read($session_id)
{
if (isset($this->_memcached) && $this->_get_lock($session_id))
{
// Needed by write() to detect session_regenerate_id() calls
$this->_session_id = $session_id;
$session_data = (string) $this->_memcached->get($this->_key_prefix.$session_id);
$this->_fingerprint = md5($session_data);
return $session_data;
}
return $this->_fail();
}
这是我的Docker配置:
FROM php:7.1.8-apache
# AUTHOR
MAINTAINER Development
# INSTALLING PACKAGES
RUN apt-get update && apt-get install -y \
git \
pkg-config \
build-essential \
libmemcached-dev \
libmemcached-tools \
libicu-dev \
libmcrypt-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libfreetype6 \
libfontconfig \
libxml2-dev \
vim \
nano \
mysql-client \
libldap2-dev \
wget
RUN apt-get clean
# Extension PHP
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install intl
RUN docker-php-ext-install mbstring
RUN docker-php-ext-install bcmath
RUN docker-php-ext-install mcrypt
RUN docker-php-ext-install zip
RUN docker-php-ext-install exif
RUN docker-php-ext-install soap
RUN docker-php-ext-install opcache
RUN docker-php-ext-install iconv
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
# APCu
RUN pecl channel-update pecl.php.net
RUN pecl install apcu
RUN echo "extension=apcu.so" > /usr/local/etc/php/conf.d/apcu.ini
# Enable PHP 7
RUN a2enmod rewrite && a2enmod headers && a2enmod expires
RUN a2enmod php7
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
# SETUP VIRTUAL HOST
COPY .docker/sites-available/default-vhost.conf /etc/apache2/sites-available/default-vhost.conf
COPY .docker/sites-available/my-vhost.conf /etc/apache2/sites-available/my-vhost.conf
RUN a2dissite 000-default.conf
RUN a2ensite default-vhost.conf
RUN a2ensite my-vhost.conf
# Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# Memcached
RUN apt-get update
RUN apt-get install -y pkg-config build-essential libmemcached-dev
RUN git clone https://github.com/php-memcached-dev/php-memcached.git
RUN cd php-memcached && git checkout php7 && phpize && ./configure --disable-memcached-sasl && make && make install
RUN echo 'extension = memcached.so' > /usr/local/etc/php/conf.d/memcached.ini
# ALIASES
RUN echo "alias ll='ls -l'" >> /root/.bashrc
RUN echo "alias la='ls -l'" >> /root/.bashrc
# COPY THE WORKING DIRECTORY
COPY . /var/www/myproject
# MANAGE DIRECTORY PERMISSIONS
RUN chown -R www-data:www-data /var/www/myproject
# SERVER RESTART
RUN service apache2 restart
这是docker-compose.yml
设置
version: '3'
services:
app:
build:
context: .
dockerfile: .docker/Dockerfile
container_name: gaz-container
image: gaz-docker
ports:
- "80:80"
volumes:
- .:/var/www/gaz
links:
- memcached:memcached
- mysql:mysql
memcached:
image: memcached
ports:
- "11211:11211"
mysql:
container_name: mysql
image: mysql:5.6
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
有人可以告诉我这里可能是什么问题吗?
答案 0 :(得分:0)
OMG。
经过大量搜索,我终于设法使它正常工作。
感谢 dukebody 。这篇文章帮助我了解我做错了什么。 https://stackoverflow.com/a/27657937/4342075
问题是我实际上正在创建多个docker容器,正如您在 docker-compose.yml 文件中的问题中看到的那样。其中之一是memcached
。我试图在主容器app
中使用memcached。
我做错了,我正在使用localhost:11211
访问memcached。
我刚刚改变
$config['sess_save_path'] = 'localhost:11211:128'
收件人
$config['sess_save_path'] = 'memcached:11211';
猜猜它能起到什么作用!!!