Laravel : Redis No connection could be made : [tcp://127.0.0.1:6379]

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Laravel : Redis No connection could be made : Resolving "tcp://127.0.0.1:6379" Issues Body:

You have installed redis with laravel by adding "predis/predis":"~1.0", and then for testing, you added the code shown below:

public function showRedis($id = 1)
   {
      $user = Redis::get('user:profile:'.$id);
      Xdd($user);
   }

In app/config/database.php, you have the following configuration for Redis:
'redis' => [
        'cluster' => false,
        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],

    ],
You receive the error No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]. You are using a virtual host for your project and Xampp with Windows, and you still encounter issues. This blog post will help you solve this problem. To start, ensure that Redis is running on your local machine. If not, install and run the Redis server by following these instructions: https://redis.io/docs/getting-started/. In addition, check if Redis is listening on the specified port (6379) using commands like "netstat -anp | grep 6379" or "lsof -i tcp:localhost:6379". If you see connections established to this port, proceed with the next steps. Now, let's ensure your Laravel project is configured correctly for using Redis as described in your database.php configuration file. Follow these best practices to avoid common errors: - Ensure the cluster option is set to false. This indicates that you are not running a distributed Redis setup. - Set the 'host' value to "localhost" or the actual server IP address where the Redis server is running. - Check if your app/config/database.php file contains the necessary environment variables for REDIS_HOST, REDIS_PASSWORD, and REDIS_PORT. Ensure these variables are set to appropriate values as per your environment. - If password authentication is enabled in Redis, provide the correct credentials (password) in the 'default' configuration block of your database.php file. - Test the connection by manually running a command like "redis-cli -h $REDIS_HOST -p 6379". This will connect to your Redis server and confirm a successful connection. If you encounter any errors, consider troubleshooting the Redis setup as per their official documentation. After ensuring your Laravel project is configured correctly for using Redis, run "composer update" or "npm install" if your project uses npm. This ensures that all dependencies are updated, including predis/predis. In case of any configuration issues in Laravel's database.php file, consider checking the official documentation for a better understanding of how to configure Redis with Laravel: https://laravel.com/docs/9.x/redis. Lastly, if you still encounter connection issues, try using different ports or IP addresses as per your environment settings and ensure they are correct in your database configuration file. For more assistance regarding Redis setup and configuration, refer to the official Redis documentation: https://redis.io/docs/. In summary, resolving "tcp://127.0.0.1:6379" issues involves ensuring proper Redis server installation, checking port availability, verifying your Laravel project's database configuration file, and troubleshooting any potential errors or misconfigurations along the way. By following these steps, you can successfully establish a connection between your Laravel app and the Redis server.