How do I make PHP store sessions in redis on RHEL/CentOS?

rickatech asked:

Have some development and staging VM’s running RHEL 7.2 with PHP5.6 via webtatic repo.

Have both Apache w/PHP and Node.js running fine. Have redis deamon running fine.

Have not found a good best practice for enabling PHP to store sessions in redis. I see reference to phpredis, but it looks like it needs to be build from source? … predis? … not an RPM via yum?

  • php-nrk-Predis ?
  • php-pecl-redis ?
  • or just edit php.ini raw?
  • Some combination of the above?

Ultimate Goal: enable both Apache/PHP and Node.js to share session in redis on same dev instance

My answer:


You really only have one choice.

nrk/Predis is a PHP class which allows you to write programs that can read and write objects to Redis. This isn’t what you’re looking for here (though you may find it useful elsewhere).

phpredis/phpredis and php-pecl-redis are exactly the same thing. This is what you are looking for; it allows PHP to store sessions in redis. Keep in mind that you have to edit your php.ini or an included file to specify to store sessions in redis and provide connection information.

(And since you’re interested in best practices, be aware that using webtatic isn’t one. In most cases you should be obtaining PHP from remi’s repositories).


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.