简体   繁体   中英

Redis for session handling of symfony applications deployed on Apache httpd

I am new to PHP, Symfony and Redis and have a query around integration of Redis with a symfony project deployed on Apache httpd as the server for session management.

The below is the software's and their versions that I am using

OS - CentOS 7 Redis - 3.2.4 - Built Redis from the source code Symfony - 2.8 PHP 7 - Installed the below packages

  • php70w
  • php70w-cli
  • php70w-common
  • php70w-fpm
  • php70w-opcache
  • php70w-pdo
  • php70w-pear
  • php70w-process
  • php70w-xml
  • php70w-pecl-redis

I have made the below entries in php.ini file

session.save_handler =  redis  
session.save_path = "tcp://<<ip address of redis server>>:6379"  
session.auto_start = 1 

What is confusing me is do I have to write session management through my symfony code using phpredis client or should it happen automatically.

Please let me know which method I should use to go further as the redis server does not seem to be populated with the session.

All the above configurations have been done by referring the below link and has been made centos specific

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04

Thanks.

You have to change default session handler. To omit Symfony session handler and use PHP instead set the handler_id option to null in settings.yml :

framework:
    session:
        handler_id: null

http://symfony.com/doc/current/reference/configuration/framework.html#handler-id

The problem was with Apache server on which I had hosted my Symfony application.

Apache had mod_php enabled and in Apache's conf.d folder I had a file named php.conf . It had properties like the ones below

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"

I commented the above values and added the below and it worked. It looks like the configuration values present in php.conf in Apache's conf.d folder overrides the value of the same properties present in php.ini .

php_value session.save_handler "redis"
php_value session.save_path    "tcp://<ip address of redis>:6379"

After making the below changes I have been able to see my php sessions on my redis server.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM