Body: <p>I am getting this error while loading <strong><em>index.php</em></strong> file.</p>
  
  <blockquote>
    <p><strong>Warning:</strong> session_start(): Cannot find save handler 'redis' - session startup failed in /var/www/html/index.php on line 2</p>
  </blockquote>
  
  <p>My index.php code looks like below:</p>
  
  <pre><code>&lt;?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);
  
  ?&gt;
  </code></pre>
  
  <p>My dockerfile is like below:</p>
  
  <pre><code>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 \
  &amp;&amp;  rm -rf /tmp/pear \
  &amp;&amp;  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" &gt; ~/.zshrc';
  </code></pre>
  
  <p>My php.ini file is like below:</p>
  
  <pre><code>session.save_handler = redis
  session.save_path = tcp://192.168.0.24:6379
  </code></pre>
  
  <p>Redis.conf file has a below entry:</p>
  
  <pre><code>bind 127.0.0.1 192.168.0.24
  </code></pre>
  
  <p>My redis dockerfile is like below:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>If I need to provide more details please let me know.</p>
  
  <p>What could be the problem here?</p>
  
Comments: CC BY-SA 4.0
Comments: 2018-05-05T17:03:22.303Z
Comments: 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?
Comments: Xiong Chiamiov
Comments: CC BY-SA 4.0
Comments: 2018-05-06T14:55:21.753Z
Comments: 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.
Comments: Gaurav Bhaskar
Comments: CC BY-SA 4.0
Comments: 2019-12-23T10:38:19.380Z
Comments: Could you post an answer?
Comments: 030
Tags: <docker><dockerfile><php><redis><composer>
Title: Can not find save handler 'redis' - session startup failed - for PHP
UserDisplayName: Gaurav Bhaskar
ThreadText: # Can not find save handler 'redis' - session startup failed - for PHP
  
  (Asked by: username_0 on 2018-05-04)
  
  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?
  
  **Tags:** docker, dockerfile, php, redis, composer
  
  > **Comments:**
  > **username_1**: 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?  
  > **username_0**: 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.  
  > **username_2**: Could you post an answer?  
  
  ---
  
  ## 0 answers
  
  