Question

Having trouble connecting Laravel 6.2 (phpredis, php7.3) to DigitalOcean Managed Redis instance

I’m looking to scale my application from a single server to multiple, so I’ve set up a brand new Redis managed database. After trying to point my Laravel app to use it I’m getting a read error on connection error. Having scouted around the internet for the best part of a day, I’ve realised that it doesn’t seem to be a common issue. I’m running Laravel 6.2, phpredis 5.1.1 and php 7.3.13. I’ve allowed my droplet to access the Redis instance over private networking.

Error

My config/database looks like this:

'redis' => [

			'client'  => 'phpredis',
			'cluster' => false,

			'default' => [
				'scheme'   => 'tls',
				'host'     => env('REDIS_HOST', '127.0.0.1'),
				'password' => env('REDIS_PASSWORD', null),
				'port'     => env('REDIS_PORT', 6379),
				'database' => env('REDIS_DB', 0),
			],

			'cache'   => [
				'scheme'   => 'tls',
				'host'     => env('REDIS_HOST', '127.0.0.1'),
				'password' => env('REDIS_PASSWORD', null),
				'port'     => env('REDIS_PORT', 6379),
				'database' => env('REDIS_CACHE_DB', 1),
			],
			'options' => [
				'prefix'     => env('REDIS_PREFIX', Str::slug(env('APP_ENV', 'ENVNOTDEFINED'), '_').'_database_'),
				'parameters' => ['password' => env('REDIS_PASSWORD', null)],
			],
		]

And my .env file contains the required values:

REDIS_HOST=DATABASE_URL.db.ondigitalocean.com
REDIS_PASSWORD=PASSWORD
REDIS_PORT=25061

I found this question, but because I’m already running later versions than the suggested fix, the answer didn’t solve my problem.

Has anyone encountered this before?


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.

Bobby Iliev
Site Moderator
Site Moderator badge
February 10, 2020
Accepted Answer

Hi @Ekion2,

This is a good question!

I’ve set up a fresh Laravel project and a Redis Managed database to test this.

I think that you’ve done everything correctly, one thing that I had to do in order to get it working was to update the REDIS_HOST and append tls://:

REDIS_HOST=tls://DATABASE_URL.db.ondigitalocean.com

Let me know how it goes! Regards, Bobby

Thanks for the suggestion @bobbyiliev, it worked like a charm! Hopefully this can help someone else out too!

@bobbyiliev You’re the man thanks!

Try DigitalOcean for free

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

Sign up

Featured on Community

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