Using redis for php session brings a lot of advantages, such as faster responsiveness to your website, however the down side could be not very stable and you may lose all redis cache on server reboot. As long as we have a HA setup of redis server we can prevent such thing from happening.
My setup: CentOS 7 + PHP 7 from Remi. There are a few gotchas to this specific setup.
Install redis and php-pecl-redis
from yum. Start redis. Now edit the files:
- No need to add
session.save_handler
in/etc/php.ini
, instead comment it out. - Modify the session handler and path in
/etc/php.d/50-redis.conf
- Restart php-fpm service.
Here is the gotcha:
When runing phpinfo();
I still see local and master values are still files
, the settings are not in effect. Then I found out that /etc/php-fpm.d/www.conf
has embedded a few php values:
php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php/session
Comment them out and restart php-fpm, your sessions are now stored in redis instead of files. Use the following php script to verify: