Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anjanesh's avatar

Redis on WSL and Laravel on Windows 11

I have installed redis on WSL on Windows 11. https://redis.io/docs/getting-started/installation/install-redis-on-windows/

redis server is running.

Now, how do I connect to it from my Windows based laravel app - I mean, the redis is running on a port on my Ubuntu based WSL - and my Laravel app is on my Windows 11 (xampp) - how do I make the connection from Windows to WSL on localhost ?

0 likes
3 replies
SleeplessDev's avatar

Hey @anjanesh

I read your blog post, so I guess you managed to get something going on your end, but for posterity I'll post my alternative solution here.

I think your method was a bit overly complicated and insecure, as you disabled Redis' protected-mode, without setting up any firewall rules to restrict access. This could open up your Redis server to the entire internet.

Your Windows OS can access the localhost address of your WSL distro, so once you get Redis server running, you just need to point Laravel to 127.0.0.1:6379.

Install WSL

  1. wsl --install
  2. I also had to run Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux in a PowerShell window with elevated privileges

WSL Install Reference

Redis Setup Reference

Get Ubuntu Ready

  1. Install Redis server:
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

sudo apt-get update
sudo apt-get install redis
  1. Enable Redis service so it will start automatically on boot: sudo systemctl enable redis-server.service
  2. Start Redis service for this session: sudo service redis-server start
  3. Launch Redis CLI: redis-cli
  4. Monitor server to confirm connection later: monitor

Redis-Server Setup Reference

Set-up Laravel

This part should be super easy if your using the default Laravel configuration. For simplicity, I'll be using the Predis client installed via Composer. Note: I'm using Laravel 10, configuration for older versions may differ.

  1. Install Predis: composer require predis/predis
  2. Setup your .env variables:
CACHE_DRIVER=redis
...
REDIS_CLIENT=predis  
REDIS_HOST=127.0.0.1  
REDIS_PASSWORD=  
REDIS_PORT=6379

Predis Install Reference

Redis Config Reference

Testing

Let's launch Tinker so we can verify our Laravel app has access to the Redis server running in WSL.

  1. Launch Tinker: php artisan tinker
  2. Test cache: cache()->put('test', 'Hello World!')
  3. If you're still running monitor from your redis-cli through your WSL terminal, you should see a log of interactions with your application.

A Note On Security

If you have some special circumstances that require you to access your redis-server over the internet, I do not recommend disabling protected-mode if at all possible.

If you absolutely have to disable it, make sure to configure ACL's for Redis, and ensure your connecting to it over a secure internet connection. If you're using public WIFI, turn on your VPN.

Redis ACL Reference

Alternative Measures

Here are some starting points for alternative options if communicating over localhost doesn't suit your use-case:

  • Only allow incoming requests for your PC's IP address. See Routing Tables
  • Configure your Ubuntu distro's routing table to forward requests from your PC to 127.0.0.1:6379 on the virtualized distro. See This Blog Post
2 likes
anjanesh's avatar

@SleeplessDev "so once you get Redis server running, you just need to point Laravel to 127.0.0.1:6379" Isn't 127.0.0.1 the Windows host IP ? In my blog I mentioned $redis->connect('172.20.143.242', 6379); where 172.20.143.242 is the WSL IP that a Windows script needs to connect to.

SleeplessDev's avatar

@anjanesh The WSL localhost address is connected to your Windows localhost, so they can talk to each other without having to use the VM's public IP address. Which is very convenient because you don't have to worry about making requests over the wire.

Please or to participate in this conversation.