DEV Community

Cover image for Redis on Windows with Laragon and Laravel: The PATH Issue That Looks Like a Redis Issue
Tahsin Abrar
Tahsin Abrar

Posted on

Redis on Windows with Laragon and Laravel: The PATH Issue That Looks Like a Redis Issue

A few days ago, I was working on a Laravel project on Windows. The project needed Redis for cache and queue handling, and since I was using Laragon, I thought the setup would be simple.

Diagram

Laragon already had Redis inside its bin folder. I started Redis, opened the terminal, and ran:

redis-cli ping
Enter fullscreen mode Exit fullscreen mode

It returned:

PONG
Enter fullscreen mode Exit fullscreen mode

Perfect.

Then I moved to my Laravel project folder, opened Git Bash, and tried the same command again.

redis-cli ping
Enter fullscreen mode Exit fullscreen mode

This time, I got:

bash: redis-cli: command not found
Enter fullscreen mode Exit fullscreen mode

At first, it looked like Redis was not installed properly. Then I wondered if Redis only worked inside Laragon’s www folder. Maybe my Laravel project was outside the correct directory?

But the real problem was much simpler.

It was not a Redis problem.

It was not a Laravel problem.

It was not a project folder problem.

It was a PATH problem.

In this post, I’ll walk through the full Redis setup on Windows using Laragon, how to make redis-cli work from Git Bash, and how to connect it properly with a Laravel project.


The Real Situation

My Laravel project was not inside Laragon’s default www folder. It was somewhere like this:

C:\Users\Asus\Downloads\aromablendbd
Enter fullscreen mode Exit fullscreen mode

But Laragon was installed here:

D:\C-data\laragon
Enter fullscreen mode Exit fullscreen mode

When I opened Laragon’s own terminal or Cmder, this worked:

redis-cli ping
Enter fullscreen mode Exit fullscreen mode

Output:

PONG
Enter fullscreen mode Exit fullscreen mode

But inside Git Bash from my Laravel project folder, the same command failed:

bash: redis-cli: command not found
Enter fullscreen mode Exit fullscreen mode

This is where the confusion started.

Redis itself does not care where your Laravel project is located. Redis runs as a server, usually on:

127.0.0.1:6379
Enter fullscreen mode Exit fullscreen mode

So any project can connect to it, whether the project is inside www, Downloads, Desktop, or another drive.

The only issue was that Git Bash did not know where redis-cli.exe was located.

Laragon’s terminal automatically adds Laragon tools to its PATH. Git Bash does not.


Step 1: Find the Redis CLI File

First, we need to find the actual redis-cli.exe file inside Laragon.

In Git Bash, run:

find /d/C-data/laragon/bin -iname "redis-cli.exe"
Enter fullscreen mode Exit fullscreen mode

Your Laragon path may be different. For example, if Laragon is installed in C:\laragon, you may need:

find /c/laragon/bin -iname "redis-cli.exe"
Enter fullscreen mode Exit fullscreen mode

In my case, the result was:

/d/C-data/laragon/bin/redis/redis-x64-5.0.14.1/redis-cli.exe
Enter fullscreen mode Exit fullscreen mode

This confirmed that Redis CLI was already installed. Git Bash simply could not find it globally.


Step 2: Test Redis Using the Full Path

Before changing PATH settings, it’s always good to test the command directly.

I ran:

/d/C-data/laragon/bin/redis/redis-x64-5.0.14.1/redis-cli.exe ping
Enter fullscreen mode Exit fullscreen mode

And the output was:

PONG
Enter fullscreen mode Exit fullscreen mode

That was the important moment.

It confirmed three things:

Redis was installed.

Redis server was running.

Git Bash could reach Redis when I used the full path.

So the server was fine. The port was fine. The Laravel folder location was fine.

Only the command shortcut was missing.


Step 3: Add Redis CLI to Git Bash PATH

To make redis-cli available from any folder in Git Bash, I added the Redis folder to ~/.bashrc.

Here is the command I used:

echo 'export PATH="$PATH:/d/C-data/laragon/bin/redis/redis-x64-5.0.14.1"' >> ~/.bashrc
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

After that, I tested again:

redis-cli ping
Enter fullscreen mode Exit fullscreen mode

This time, it worked:

PONG
Enter fullscreen mode Exit fullscreen mode

Now I could run redis-cli from any folder, including my Laravel project folder.

This is the clean fix for the redis-cli: command not found issue in Git Bash.


A Small Redis CLI Mistake That Can Confuse You

At one point, I entered the Redis shell by running:

redis-cli
Enter fullscreen mode Exit fullscreen mode

Then the terminal changed to something like this:

127.0.0.1:6379>
Enter fullscreen mode Exit fullscreen mode

Inside this prompt, I tried:

redis-cli ping
Enter fullscreen mode Exit fullscreen mode

That was wrong.

When you are inside the Redis shell, you should only write Redis commands.

Correct:

ping
Enter fullscreen mode Exit fullscreen mode

Output:

PONG
Enter fullscreen mode Exit fullscreen mode

Wrong:

redis-cli ping
Enter fullscreen mode Exit fullscreen mode

Why?

Because redis-cli is a terminal command. It starts the Redis command-line tool.

But once you are already inside Redis CLI, you only need to type Redis commands like:

ping
set name laragon
get name
exit
Enter fullscreen mode Exit fullscreen mode

So there are two valid ways to test Redis.

From the normal terminal:

redis-cli ping
Enter fullscreen mode Exit fullscreen mode

Or from inside the Redis shell:

redis-cli
Enter fullscreen mode Exit fullscreen mode

Then:

ping
Enter fullscreen mode Exit fullscreen mode

Both are correct, but they are used in different places.


Step 4: Make Sure Redis Server Is Running

If you installed the full version of Laragon, Redis is usually included inside the Laragon bin directory.

A common Redis path looks like this:

C:\laragon\bin\redis\redis-x64-3.2.100
Enter fullscreen mode Exit fullscreen mode

Or in my case:

D:\C-data\laragon\bin\redis\redis-x64-5.0.14.1
Enter fullscreen mode Exit fullscreen mode

You can start Redis by running:

redis-server.exe
Enter fullscreen mode Exit fullscreen mode

Or from Git Bash, using the full path:

/d/C-data/laragon/bin/redis/redis-x64-5.0.14.1/redis-server.exe
Enter fullscreen mode Exit fullscreen mode

Once the Redis server is running, keep that terminal open.

To stop the server later, press:

Ctrl + C
Enter fullscreen mode Exit fullscreen mode

Laragon may also let you manage Redis from its menu depending on your installation.

One important note: Redis native Windows support is limited, and many Windows setups use older Redis builds. For the latest Redis versions, Docker, WSL, or Laradock can be a better option. But for local Laravel development, Laragon’s Redis works well enough in many cases.


Step 5: Configure Laravel .env

After Redis worked in the terminal, the next step was Laravel.

In the Laravel project, I opened the .env file and checked the Redis settings.

For my setup, I used:

REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
Enter fullscreen mode Exit fullscreen mode

If you want to use Redis for cache, also check your cache setting.

For newer Laravel versions:

CACHE_STORE=redis
Enter fullscreen mode Exit fullscreen mode

For older Laravel versions:

CACHE_DRIVER=redis
Enter fullscreen mode Exit fullscreen mode

The key point is this:

Laravel does not need the redis-cli command to connect to Redis.

Laravel connects to Redis through PHP using the host and port:

127.0.0.1:6379
Enter fullscreen mode Exit fullscreen mode

So even if redis-cli was not available in Git Bash, Laravel could still connect if the Redis client package or PHP extension was correctly installed.


Step 6: Install Laravel Dependencies

If this is an existing Laravel project, run:

composer install
Enter fullscreen mode Exit fullscreen mode

This installs the dependencies listed in composer.json.

In my case, Laravel was configured to use Predis:

REDIS_CLIENT=predis
Enter fullscreen mode Exit fullscreen mode

But when I tested Redis in Laravel, I got this error:

Class "Predis\Client" not found
Enter fullscreen mode Exit fullscreen mode

That means Laravel wanted to use Predis, but the package was not installed.

The fix was simple:

composer require predis/predis
Enter fullscreen mode Exit fullscreen mode

After installing Predis, I cleared Laravel’s cached config:

php artisan config:clear
php artisan cache:clear
php artisan optimize:clear
Enter fullscreen mode Exit fullscreen mode

This step is important because Laravel may keep old .env or config values in cache.


Predis vs PhpRedis

Laravel can use Redis in two common ways.

The first option is Predis.

REDIS_CLIENT=predis
Enter fullscreen mode Exit fullscreen mode

For this, install the Composer package:

composer require predis/predis
Enter fullscreen mode Exit fullscreen mode

This is often the easiest option when you are working on Windows and want a quick local setup.

The second option is PhpRedis.

REDIS_CLIENT=phpredis
Enter fullscreen mode Exit fullscreen mode

For this, you need the PHP Redis extension enabled.

In Laragon, the Redis PHP extension does not always come enabled by default. You may need to download the correct php_redis.dll file that matches your PHP version, architecture, and thread-safety build.

You can check your PHP version from Laragon. Then download the matching Redis extension DLL from PECL:

https://pecl.php.net/package/redis
Enter fullscreen mode Exit fullscreen mode

After downloading, copy:

php_redis.dll
Enter fullscreen mode Exit fullscreen mode

Into your PHP extension folder, for example:

C:\laragon\bin\php\php-8.x.x\ext
Enter fullscreen mode Exit fullscreen mode

Then add this line to your php.ini file:

extension=php_redis.dll
Enter fullscreen mode Exit fullscreen mode

Restart Laragon after making the change.

For many local projects, Predis is simpler. For better performance in some production setups, PhpRedis is commonly used.


Step 7: Test Redis from Laravel Tinker

Now came the final test.

From the Laravel project folder, I ran:

php artisan optimize:clear
php artisan tinker
Enter fullscreen mode Exit fullscreen mode

Inside Tinker, I first tried:

Redis::connection()->ping();
Enter fullscreen mode Exit fullscreen mode

But I got:

Class "Redis" not found
Enter fullscreen mode Exit fullscreen mode

This does not always mean Redis is broken. It can simply mean the Redis facade was not imported in Tinker.

The safer way is to use the full namespace:

\Illuminate\Support\Facades\Redis::connection()->ping();
Enter fullscreen mode Exit fullscreen mode

Or use Laravel’s service container:

app('redis')->connection()->ping();
Enter fullscreen mode Exit fullscreen mode

Expected output:

"PONG"
Enter fullscreen mode Exit fullscreen mode

When I saw "PONG" from Laravel Tinker, the setup was finally complete.

At that point, Redis was working in three places:

From Laragon terminal.

From Git Bash.

From Laravel itself.


Common Errors and What They Really Mean

bash: redis-cli: command not found

This means your terminal cannot find redis-cli.exe.

It does not mean Redis is not installed.

Fix it by adding the Redis folder to Git Bash PATH:

echo 'export PATH="$PATH:/d/C-data/laragon/bin/redis/redis-x64-5.0.14.1"' >> ~/.bashrc
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Then test:

redis-cli ping
Enter fullscreen mode Exit fullscreen mode

Class "Predis\Client" not found

This means Laravel is using Predis, but the package is missing.

Fix:

composer require predis/predis
php artisan optimize:clear
Enter fullscreen mode Exit fullscreen mode

Class "Redis" not found

This may happen in Tinker when the Redis facade is not imported.

Use the full namespace:

\Illuminate\Support\Facades\Redis::connection()->ping();
Enter fullscreen mode Exit fullscreen mode

Or:

app('redis')->connection()->ping();
Enter fullscreen mode Exit fullscreen mode

Redis Works in www but Not in Another Folder

This is usually not a folder issue.

Laragon terminal automatically sets PATH for Laragon tools. Git Bash does not.

Redis runs on:

127.0.0.1:6379
Enter fullscreen mode Exit fullscreen mode

So your Laravel project can be anywhere as long as Redis is running and Laravel is configured correctly.


Final Working Setup

Here is the final setup that worked for me.

Redis CLI path:

/d/C-data/laragon/bin/redis/redis-x64-5.0.14.1/redis-cli.exe
Enter fullscreen mode Exit fullscreen mode

Git Bash PATH fix:

echo 'export PATH="$PATH:/d/C-data/laragon/bin/redis/redis-x64-5.0.14.1"' >> ~/.bashrc
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Redis terminal test:

redis-cli ping
Enter fullscreen mode Exit fullscreen mode

Expected:

PONG
Enter fullscreen mode Exit fullscreen mode

Laravel .env:

REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
CACHE_STORE=redis
Enter fullscreen mode Exit fullscreen mode

Install Predis:

composer require predis/predis
Enter fullscreen mode Exit fullscreen mode

Clear Laravel config:

php artisan config:clear
php artisan cache:clear
php artisan optimize:clear
Enter fullscreen mode Exit fullscreen mode

Test in Tinker:

php artisan tinker
Enter fullscreen mode Exit fullscreen mode

Then:

\Illuminate\Support\Facades\Redis::connection()->ping();
Enter fullscreen mode Exit fullscreen mode

Expected:

"PONG"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)