Question

How to configure Laravel 5.7 with Redis TLS (Using phpredis)

Hi

I’m using laravel 5.7 with phpredis (PHP 7.2), but I’m not able to get it to work with tls, I am trying to use it with digitalocean Redis managed database which only supports tls connections.

Any idea if tls even supported with laravel/phpredis?

Show comments

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.

Accepted Answer

So I managed to get this to work, basically the current phpredis version that is shipped with php 7.2 (Ubuntu 18) is old and does not support tls, to fix this I had to update phpredis from pecl (https://pecl.php.net/package/redis)

Error

Error while reading line from the server. [tls://private-XXX-do-user-XXX-0.b.db.ondigitalocean.com:25061]

Reason

DigitalOcean Managed Redis is not compatible with Predis.

Solution

Remove Predis and use phpredis. Phpredis is an extension for PHP.

  1. Check if you have installed phpredis:
# php -i | grep async_redis
async_redis => enabled
  1. Remove predis from your composer.json and add this line (good practice):
"require": {
    "php": "^8.0",
    /* ... */
    "ext-redis": "*",
    /* ... */

  1. Change your code or .env REDIS_CLIENT value:
'redis' => [
    'client' => env('REDIS_CLIENT', 'phpredis'),

    'default' => [
        'scheme' => env('DATA_REDIS_SCHEME', 'tcp'),
        'host' => env('DATA_REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => 0,
        // 'read_write_timeout' => 0, // is not required for DO anymore, but just in case...
    ],

    'cache' => [
    ],
],
Bobby Iliev
Site Moderator
Site Moderator badge
February 16, 2020

Hello,

I’ve created a step by step guide on how to do that along with a short video demo for anyone who is experiencing the same issue:

https://www.digitalocean.com/community/questions/how-to-setup-laravel-with-digitalocean-managed-redis-cluster

Hope that this helps! Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel