2

I am getting this error while loading index.php file.

Warning: session_start(): Cannot find save handler 'redis' - session startup failed in /var/www/html/index.php on line 2

My index.php code looks like below:

<?php
session_start();
$_SESSION['count']=(isset($_SESSION['count']))?$_SESSION['count']+1:1;
$json['time ']= date(' Y-m-d H:i:s');
$json['ip ']=$_SERVER['REMOTE_ADDR'];
$json['count '] = $_SESSION['count'];
echo json_encode($json);

?>

My dockerfile is like below:

FROM php:7.1-fpm-alpine

RUN apk update; \
    apk upgrade;

RUN apk add --update \
        autoconf \
        g++ \
        libtool \
                make

RUN pecl install -o -f redis \
&&  rm -rf /tmp/pear \
&&  docker-php-ext-enable redis


# For easy navigating add oh my zsh and it's deps
RUN apk -q add curl \
    zsh \
    nano \
    git; \
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"; \
    sed -i s^ZSH_THEME=\"robbyrussell\"^ZSH_THEME=\"blinks\"^g ~/.zshrc;

# Install Composer
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');"; \
    echo 'alias composer="php /var/www/html/composer.phar" > ~/.zshrc';

My php.ini file is like below:

session.save_handler = redis
session.save_path = tcp://192.168.0.24:6379

Redis.conf file has a below entry:

bind 127.0.0.1 192.168.0.24

My redis dockerfile is like below:

FROM redis:3.2-alpine

COPY conf/redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

EXPOSE 6379

If I need to provide more details please let me know.

What could be the problem here?

  • How are you running these containers? Inter-container networking in Docker is rather tricky and not straight-forward. Can you access redis from your host machine? – Xiong Chiamiov May 5 '18 at 17:03
  • Yes, however, I wanted to keep it that way. I have fixed my issue though, using a different version of phpredis. I will update this question with my answer soon. – Gaurav Bhaskar May 6 '18 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.