Question

How to configure PHP Native session with redis managed database

I’m using PHP 7.2 and I’m unable to connect a Redis managed db instance.

in /etc/php/7.2/fpm/php.ini

session.save_handler = redis
; tried either :
session.save_path = "rediss://default:mypassword@db-redis-ams3-preprod-do-user-xxx-0.a.db.ondigitalocean.com:25061"
session.save_path = "tcp://default:mypassword@db-redis-ams3-preprod-do-user-xxx-0.a.db.ondigitalocean.com:25061"
session.save_path = "tls://default:mypassword@db-redis-ams3-preprod-do-user-xxx-0.a.db.ondigitalocean.com:25061"
session.save_path = "tls://db-redis-ams3-preprod-do-user-xxx-0.a.db.ondigitalocean.com:25061?auth=mypassword"

Each time same kind of issue :

RedisException
read error on connection

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

I believe that the last line with TLS and auth defined looks correct.

I’ve just created a new Redis cluster and tested this with one of my servers where I have PHP 7.4 installed.

First I updated the PHP sessions handler:

; Old value:
;session.save_handler = files
; New value:
session.save_handler = redis

Then defined the save path:

session.save_path = "tls://redis_cluster_name.b.db.ondigitalocean.com:25061?auth=password"

After that, I restarted PHP-FPM or your Apache webserver.

Another thing that you need to keep in mind is that you need to open port 25061 for outgoing TCP connections in case that you have a firewall.

If this still does not work I could suggest trying with PHP 7.4 instead of PHP 7.2 and also make sure that you have the php-redis module installed.

For more information you could follow this tutorial here:

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

Regards, Bobby