0

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

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
rickatech
  • 141
  • 8

2 Answers2

1

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).

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • Excellent feedback. I noticed that php-pecl-redis seemed to work, but didn't know it was essentially phpredis/phpredis. Really getting tired of RH PHP being so old, will checkout remi – rickatech Sep 14 '16 at 23:03
  • @rickatech Remi is the Red Hat employee who maintains RHEL's PHP packages (among others). His own repos contain later versions of PHP which are otherwise the same. – Michael Hampton Sep 14 '16 at 23:04
  • had a go using remi instead of webtastic repo for php5.6, pretty slick. Nice write up on it at https://www.digitalocean.com/community/questions/how-to-install-php-5-6-on-centos-7-0-x64 – rickatech Sep 15 '16 at 10:09
0

Since RHEL/CentOS 7.2 doesn't have direct PHP 5.6 support, using webtatic repo (for better or for worse) for now ... this seemed to do the trick.

# yum install redis

# yum install  php56w-pecl-redis

# diff /etc/httpd/conf.d/php.conf

23,25c23,28
< php_value session.save_handler "files"
< php_value session.save_path    "/var/lib/php/session"
< php_value soap.wsdl_cache_dir  "/var/lib/php/wsdlcache"
---
> # p_value session.save_handler "files"
> php_value session.save_handler "redis"
> # p_value session.save_path    "/lib/php/session"
> php_value session.save_path    "tcp://127.0.0.1:6379"
> # p_value soap.wsdl_cache_dir  "/var/lib/php/wsdlcache"
> php_value soap.wsdl_cache_dir  "tcp://127.0.0.1:6379"

# systemctl restart redis

# systemctl restart httpd

It's important to be very sure the correct PHP override directive is active since /etc/php.ini did NOT activate this, /etc/httpd/conf.d/php.ini did. Browsing a test.php file with call to phpinfo(); quite helpful.

rickatech
  • 141
  • 8