This article explains how to set up Laravel real-time events on Windows using a local development environment. We will use:
By the end, you will be able to broadcast events from Laravel and listen to them in real time on
localhost.
Open PowerShell as Administrator and run:
wsl --install
This installs WSL and Ubuntu by default. Restart your system if prompted.
Check installation:
wsl -l -v
From Start Menu, open Ubuntu and set your Linux username and password.
Redis will be used as the broadcasting driver.
sudo apt update && sudo apt upgrade -y
sudo apt install redis-server -y
sudo service redis-server start
Verify Redis is running:
redis-cli ping
Expected output:
PONG
Redis will be available on 127.0.0.1:6379
Inside WSL:
sudo apt install php-redis -y
Restart PHP (if using PHP-FPM or Apache).
In your Laravel project directory:
php artisan install:broadcasting
This enables broadcasting configuration.
.envBROADCAST_CONNECTION=redis
QUEUE_CONNECTION=redis
CACHE_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
config/broadcasting.phpMake sure Redis is enabled:
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
Open config/app.php and ensure:
App\Providers\BroadcastServiceProvider::class,
is uncommented.
Laravel Echo Server listens for broadcast events and pushes them via WebSockets.
npm install -g laravel-echo-server
From your Laravel root:
laravel-echo-server init
Example answers:
? Do you want to run this server in development mode? Yes
? Which port would you like to serve on? 6001
? Which database would you like to use to store presence channel members? redis
? Enter the host of your Laravel authentication server: http://localhost
? Will you be serving on http or https? http
? Do you want to generate a client ID/Key? Yes
This creates laravel-echo-server.json.
laravel-echo-server.json{
"authHost": "http://localhost",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "local",
"key": "localkey"
}
],
"database": "redis",
"databaseConfig": {
"redis": {
"host": "127.0.0.1",
"port": 6379
}
},
"devMode": true,
"host": null,
"port": 6001,
"protocol": "http",
"socketio": {},
"secureOptions": 67108864
}
laravel-echo-server start
You should see:
✔ Running at http://localhost:6001
✔ Listening for events...
npm install laravel-echo socket.io-client
resources/js/bootstrap.jsimport Echo from 'laravel-echo';
import io from 'socket.io-client';
window.io = io;
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
Run build:
npm run dev
php artisan make:event MessageSent
app/Events/MessageSent.php:
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class MessageSent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public string $message;
public function __construct($message)
{
$this->message = $message;
}
public function broadcastOn()
{
return new Channel('chat');
}
}
use App\Events\MessageSent;
Route::get('/send', function () {
broadcast(new MessageSent('Hello from Laravel'));
return 'Event Sent';
});
window.Echo.channel('chat')
.listen('MessageSent', (e) => {
console.log(e.message);
});
Open browser console and visit:
http://localhost/send
You should see the message instantly.
ShouldBroadcastroutes/channels.phpBroadcast::channel('chat', function () {
return true;
});
Broadcasting uses queues. Ensure worker is running:
php artisan queue:work
| Issue | Solution |
|---|---|
| Events not firing | Check Redis running |
| Echo not connecting | Check port 6001 and Echo Server status |
| Auth error | Verify authHost and authentication routes |
| No output | Run queue worker with php artisan queue:work |
Using WSL + Redis + Laravel Echo Server, you can easily run real-time Laravel events on Windows with a local setup. This approach closely matches production environments and provides fast, reliable WebSocket communication.
Happy Coding 🚀