Saving PHP Sessions in Redis

phpinfo查看是否安装redis支持

Session Support    enabled
Registered save handlers    files user redis
Registered serializer handlers    php php_binary igbinary

修改配置文件php.ini

session.save_handler = redis
session.save_path="tcp://hostname:6379" #参考/etc/php.d/redis.ini中的例子

重启apache

如果是nginx+php-fpm环境则重启php-fpm

重启之后session.save_handler还是files,则可能是php-fpm的默认配置(/etc/php-fpm.d/www.conf)覆盖了php.ini
注释掉

; Set session path to a directory owned by process user
;php_value[session.save_handler] = files
;php_value[session.save_path] = /var/lib/php/session

然后重启php-fpm

测试环境:centos 6.3 + php 5.3.3 + redis 2.4 + ngnix 1.0