CodexBloom - Programming Q&A Platform

Laravel 10: Difficulty with Caching Configuration for Redis on Multiple Environments

👀 Views: 201 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-09
laravel redis caching environment-configuration php

I'm not sure how to approach I'm working on a personal project and I've been banging my head against this for hours... I'm working with issues configuring caching with Redis in Laravel 10 across different environments (local, staging, production). I've set up my `.env` files to specify the Redis connection details, but when I try to clear the cache or use caching in my application, I get the following behavior: ``` Illuminate\Cache\Exceptions\CacheException: Failed to connect to Redis at 127.0.0.1:6379: Connection refused ``` On my local setup, Redis is running, yet the application seems to be trying to connect to a Redis instance that isn't running on my staging server. I've verified that the `.env.staging` file has the correct Redis host configured: ``` REDIS_HOST=redis.staging.example.com REDIS_PASSWORD=null REDIS_PORT=6379 ``` I've also tried running `php artisan config:cache` after making changes but to no avail. In my `config/cache.php`, I've set the default cache driver to Redis: ```php 'cache' => [ 'default' => env('CACHE_DRIVER', 'redis'), ], ``` I even added logging in my application to see what configurations are being loaded and it seems to read the right `.env` variables, yet the connection is still refused. I'm running on AWS for staging and production, and I suspect there might be network or security group issues, but I need to confirm that the Laravel setup is correct first. Any suggestions on how to debug this further or confirm that the Redis connection settings are properly applied? This is part of a larger CLI tool I'm building. What's the best practice here? My development environment is macOS. How would you solve this? The stack includes Php and several other technologies. For context: I'm using Php on Linux.