Today I lost a few hours to debug the issue when I was trying to move a Laravel application to Digital Ocean.
I love Digital Ocean in the sense that it’s very user friendly, not overly complex like AWS, and fairly priced. I was eagerly waiting for the managed database to launch in Digital Ocean, which they added.
MySQL was working perfectly, but the problem occurred when I added the cache/queue server. I was scratching my head and searching all over. This is a very good resource for solving this problem.
I understood I’ve installed the Pecl Redis library as it is able to connect via TLS. Even though I’ve installed/updated the pecl extension, nothing was working.
I had checked multiple times, my configuration looks exactly like this:
REDIS_HOST=tls://redis-do-user-some-0.a.db.ondigitalocean.com REDIS_PASSWORD=THEPASSWORD REDIS_PORT=25061
I kept getting the error:
php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known [tcp://tls://wemail-cache-do-user-2557929-0.a.db.ondigitalocean.com:25061
It was skipping my mind that we have to use the
phpredis client in the Laravel config
config/database.php, not the
'redis' => [ 'client' => 'predis', 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => env('REDIS_DB', 0), 'read_timeout' => 60, 'timeout' => 5, ], ],
After changing the client, everything worked perfectly.
Note: Older Laravel version defaults to predis. The newer version, however, defaults to phpredis and expects another env variable,
REDIS_CLIENT. Predis may be removed from the framework soon due to lack of maintenance.
'client' => env('REDIS_CLIENT', 'phpredis'),