Laravel Echo with Vue: Reverb, useEcho and Moving Off Socket.io
Updated in November 2026. The post now uses Laravel Reverb and @laravel/echo-vue. The old Socket.io setup has its own section.
I wrote the first version of this post in 2020, for a Vue PWA on Netlify talking to a Laravel API on a Forge server. Pusher cost money, so the usual free route was Socket.io, Redis and laravel-echo-server. It took me a couple of hours to get running.
In 2026 laravel-echo-server is archived, and Laravel now ships its own WebSocket server.
This guide builds the same setup with current tools: a standalone Vue SPA on one origin, a Laravel API on another, private channels and notifications. I tested the code below with Laravel 13.40, Reverb 1.12, @laravel/echo-vue 2.6.3 and Vue 3.5, with the SPA and the API running on different origins. The Forge section follows Forge’s docs, I didn’t run it on a live server.
Should you still use Socket.io with Laravel?
Not for a new project. Echo’s client can still talk to Socket.io, but the server side has been left behind:
laravel-echo-serveris archived on GitHub. Its last release is 1.6.3 from January 2022, and it depends on Socket.io 2.- Laravel’s default
config/broadcasting.phpno longer has aredisconnection. The broadcaster class still exists, but you have to add the connection yourself.
Laravel Reverb replaces both pieces:
| laravel-echo-server | Reverb | |
|---|---|---|
| Runs on | Node, installed globally | PHP, installed in your app with Composer |
| Maintained | Archived | First-party Laravel package |
| Laravel sends to it | Through Redis pub/sub | Directly, using the Pusher protocol |
| Redis | Required | Only for running multiple Reverb servers |
| Browser client | socket.io-client |
pusher-js |
| Default port | 6001 | 8080 |
If you don’t want to run a WebSocket process at all, Echo also works with Pusher and Ably, and Laravel Cloud offers managed Reverb.
Install Reverb on the Laravel API
php artisan install:broadcasting --reverb --without-node
--without-node skips the frontend packages, because the SPA lives in its own repo. If your Vue app sits inside the Laravel project, leave the flag off.
The command installs Reverb, creates routes/channels.php and adds this to .env:
BROADCAST_CONNECTION=reverb
REVERB_APP_ID=your-app-id
REVERB_APP_KEY=your-app-key
REVERB_APP_SECRET=your-app-secret
REVERB_HOST="localhost"
REVERB_PORT=8080
REVERB_SCHEME=http
Old .env files use BROADCAST_DRIVER. Laravel now reads BROADCAST_CONNECTION.
Authorize private channels for a separate SPA
Out of the box, Laravel registers the channel auth route at /broadcasting/auth with session middleware. A standalone SPA sending a bearer token can’t use it. The default CORS config only covers api/*, so the browser blocks the request before it reaches your channel callback.
Install Sanctum, then move the route under api:
php artisan install:api
Add the HasApiTokens trait to your User model, then edit bootstrap/app.php. Remove the channels: line from withRouting and add withBroadcasting:
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withBroadcasting(
__DIR__.'/../routes/channels.php',
['prefix' => 'api', 'middleware' => ['api', 'auth:sanctum']],
)
The auth route is now /api/broadcasting/auth, and it accepts the same token as the rest of your API.
Tokens or cookies? Sanctum’s docs tell you to use cookie auth for a first-party SPA, and they’re right when you can. It keeps the credential away from JavaScript. Cookies need the SPA and the API on the same top-level domain, like app.example.com and api.example.com. If your frontend is on a netlify.app domain, tokens are the option you have. For cookies, keep withBroadcasting as above and follow the docs’ authorizer example.
Create the event and channel
Say your app has a countdown timer, and its owner should see the time left update without refreshing the page. That takes two things on the server: an event that carries the new value, and a private channel only the owner can join. Here’s the event:
<?php
namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class TimerUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct(public int $timerId, public int $secondsLeft)
{
}
public function broadcastOn(): PrivateChannel
{
return new PrivateChannel('timers.'.$this->timerId);
}
}
Public properties become the payload. Then decide who can listen, in routes/channels.php:
Broadcast::channel('timers.{timerId}', function ($user, int $timerId) {
return $user->timers()->whereKey($timerId)->exists();
});
ShouldBroadcast puts the event on your queue, so you need a queue worker running. Use ShouldBroadcastNow to skip the queue and send it during the request.
Set up Echo in Vue
npm install @laravel/echo-vue pusher-js
Add the connection details to the SPA’s .env, using the key from the API:
VITE_API_URL=http://localhost:8000
VITE_REVERB_APP_KEY=your-app-key
VITE_REVERB_HOST=localhost
VITE_REVERB_PORT=8080
VITE_REVERB_SCHEME=http
Vite puts VITE_ variables in your public bundle. That’s fine for the app key, which every client needs. Never add REVERB_APP_SECRET here.
configureEcho reads those VITE_REVERB_* variables on its own, so you only pass the auth details:
// src/echo.js
import { configureEcho, echo } from '@laravel/echo-vue';
export function connectEcho(token) {
configureEcho({
broadcaster: 'reverb',
authEndpoint: `${import.meta.env.VITE_API_URL}/api/broadcasting/auth`,
bearerToken: token,
});
}
export function disconnectEcho() {
echo().disconnect();
}
Most examples call configureEcho once in main.js. That doesn’t work when the token only exists after login, so call connectEcho from your login handler and render anything that listens after that:
Don’t skip the logout step. Calling configureEcho again creates a new connection but doesn’t close the old one. The nextTick lets the components unmount and leave their channels first.
Listen with useEcho
That’s all of it. The composable subscribes when the component mounts and leaves the channel when it unmounts. In the 2020 version I had to manage this by hand.
There is no useEchoPrivate
If you searched for useEchoPrivate, it doesn’t exist in @laravel/echo-vue. useEcho is the private channel composable, and other channel types have their own:
| Composable | Use it for |
|---|---|
useEcho |
Private channels |
useEchoPublic |
Public channels, no auth request |
useEchoPresence |
Presence channels |
useEchoNotification |
Laravel notifications on a private channel |
useEchoModel |
Model broadcasting events |
useConnectionStatus |
Reactive status, such as connected or failed |
useSocketId |
Reactive socket ID |
Custom event names need a leading dot
Echo prefixes event names with App.Events, which is why TimerUpdated works on its own. If your event sets a custom name with broadcastAs, add a leading dot on the client to turn the prefix off:
public function broadcastAs(): string
{
return 'timer.renamed';
}
useEcho(`timers.${props.timerId}`, '.timer.renamed', (e) => {
// ...
});
Skip the dot and Echo listens for App\Events\timer\renamed, which never arrives. You get no error.
Receive notifications
Any notification with broadcast in its via array goes to the user’s private channel. install:broadcasting already adds the auth callback for that channel:
public function via(object $notifiable): array
{
return ['broadcast'];
}
public function toBroadcast(object $notifiable): BroadcastMessage
{
return new BroadcastMessage(['message' => 'Your timer has finished']);
}
import { useEchoNotification } from '@laravel/echo-vue';
useEchoNotification(`App.Models.User.${props.userId}`, (notification) => {
console.log(notification.message, notification.type);
});
notification.type is the class name, here App\Notifications\TimerFinished. Broadcast notifications go through the queue too, even when the class doesn’t implement ShouldQueue.
How do you run Laravel Reverb locally?
You need two processes alongside your usual dev server:
php artisan reverb:start --debug
php artisan queue:work
--debug prints every message passing through Reverb, which is the fastest way to see whether an event left Laravel. Reverb is long-running, so it won’t pick up code changes until you run php artisan reverb:restart.
Deploy Reverb on Laravel Forge
This used to mean writing a Supervisor config or a daemon by hand. Now it’s a toggle. Going by Forge’s docs, turn on Laravel Reverb in the application panel on the site’s Overview tab. Forge asks for three things:
- Public hostname, which defaults to
ws.example.com - Port, for the Reverb daemon to run on
- Maximum concurrent connections, which Forge uses to raise the server’s file and Nginx limits
Forge creates the daemon, adds the Nginx proxy for that hostname and appends reverb:restart to your deploy script. Add a queue worker for the site as well.
Request an SSL certificate that covers the Reverb hostname, then set these on the API and redeploy:
REVERB_HOST=ws.example.com
REVERB_PORT=443
REVERB_SCHEME=https
Set the matching values wherever your SPA builds. On Netlify, that’s the site’s environment variables:
VITE_API_URL=https://api.example.com
VITE_REVERB_APP_KEY=your-production-key
VITE_REVERB_HOST=ws.example.com
VITE_REVERB_PORT=443
VITE_REVERB_SCHEME=https
Vite bakes these in at build time, so trigger a new deploy after changing them.
Before going live, lock down both origin lists, since both default to allowing everything. In config/reverb.php, use the hostname without a scheme or port:
'allowed_origins' => ['app.example.com'],
For HTTP requests, run php artisan config:publish cors and set allowed_origins in config/cors.php to your full SPA URL.
Not on Forge? Run reverb:start under Supervisor and proxy to it from Nginx. Reverb’s production docs have the config, including the open file limits you’ll hit past about 1,000 connections.
Troubleshooting Laravel Echo
I triggered most of these on purpose, so the messages are exact.
Echo has not been configured. A component called useEcho before configureEcho ran. Render it after login with v-if.
blocked by CORS policy on /broadcasting/auth. The SPA is calling the default route. Add withBroadcasting with the api prefix and update authEndpoint.
403 on /api/broadcasting/auth. Auth worked, and your callback in routes/channels.php returned false. If you get 401 instead, the token is missing or expired.
WebSocket connection to 'ws://localhost:8080/app/?protocol=7...' failed with a 404. Look at the URL. There’s nothing between /app/ and ?, which means VITE_REVERB_APP_KEY is empty. Restart Vite after editing .env.
{"code":4009,"message":"Origin not allowed"} in the WebSocket frames. Your SPA’s hostname isn’t in allowed_origins in config/reverb.php. The status goes to disconnected.
No errors, but events never arrive. Check three things in order. Is queue:work running? Does reverb:start --debug show the message? Did you need a leading dot on the event name?
Still running laravel-echo-server?
Moving off is smaller than it looks. Your events and routes/channels.php stay as they are, and Echo’s channel API works the same way. The work is swapping the server and the client config:
- Install Reverb and set
BROADCAST_CONNECTION=reverb. - Stop the
laravel-echo-server startdaemon and deletelaravel-echo-server.json. - Remove
socket.io-clientandwindow.iofrom the frontend, then addpusher-js. - On Vue 3, replace your Echo setup with
configureEcho, then convert listeners as you touch them. On Vue 2, use the setup below.
A listener from the old version of this post converts like this:
// Vue 2 with Socket.io
this.$echo.private(`timers.${this.game.timer.id}`).listen('.timer.updated', (e) => {
this.timer = e.timer;
});
// Vue 3 with Reverb
useEcho(`timers.${game.timer.id}`, '.timer.updated', (e) => {
timer.value = e.timer;
});
@laravel/echo-vue needs Vue 3. On Vue 2, install the plain laravel-echo package instead:
npm install laravel-echo pusher-js
Plain Echo takes the connection details as options, so the setup is longer. This version keeps the same login flow, with the instance on Vue.prototype so your existing this.$echo calls still work:
// src/echo.js
import Vue from 'vue';
import Echo from 'laravel-echo';
import Pusher from 'pusher-js';
window.Pusher = Pusher;
export function connectEcho(token) {
Vue.prototype.$echo = new Echo({
broadcaster: 'reverb',
key: import.meta.env.VITE_REVERB_APP_KEY,
wsHost: import.meta.env.VITE_REVERB_HOST,
wsPort: import.meta.env.VITE_REVERB_PORT,
wssPort: import.meta.env.VITE_REVERB_PORT,
forceTLS: import.meta.env.VITE_REVERB_SCHEME === 'https',
enabledTransports: ['ws', 'wss'],
authEndpoint: `${import.meta.env.VITE_API_URL}/api/broadcasting/auth`,
bearerToken: token,
});
}
export function disconnectEcho() {
Vue.prototype.$echo.disconnect();
}
On Vue CLI, swap import.meta.env.VITE_* for process.env.VUE_APP_*. Your listeners don’t change, but there’s no composable to clean up after you, so leave the channel yourself:
export default {
props: { timerId: Number },
data: () => ({ secondsLeft: null }),
created() {
this.$echo.private(`timers.${this.timerId}`).listen('TimerUpdated', (e) => {
this.secondsLeft = e.secondsLeft;
});
},
beforeDestroy() {
this.$echo.leave(`timers.${this.timerId}`);
},
};
Vue 2 reached end of life on December 31, 2023, so treat this as a stopgap until you can move to Vue 3.
If you have to keep it running for now
These are the things that catch people on an old install:
- Add the Redis connection back on new Laravel versions. Set
BROADCAST_CONNECTION=redisand add this toconnectionsinconfig/broadcasting.php:
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
- Pin the client to Socket.io 2. The server depends on
socket.io^2.3.0, and newer clients can’t connect to a v2 server. Installsocket.io-client@2, not thesocket.iopackage my old post told you to install. - Point auth at your API. Set
"authEndpoint": "/api/broadcasting/auth"inlaravel-echo-server.jsonif you authorize through API routes. - On Forge, run it as a daemon. Use the command
laravel-echo-server startwith your site as the working directory.
The laravel-echo-server-updated fork on npm won’t save you, as it hasn’t been updated since May 2022 either.
If you see [ioredis] Unhandled error event: Error: connect ECONNREFUSED 192.168.10.10:6379, Redis isn’t listening on the address the echo server is using. Add that IP to the bind line in /etc/redis/redis.conf and restart Redis, or point the server at 127.0.0.1 if both run on the same machine.
Q&A
Q: What’s the difference between Laravel Echo and Reverb? A: Echo is the JavaScript library in your frontend that subscribes to channels. Reverb is the WebSocket server that sends it messages. You use them together, so it isn’t an either-or choice.
Q: Can I use Socket.io with Laravel Reverb?
A: No. Reverb speaks the Pusher protocol, so your frontend connects with pusher-js. To move off Socket.io, swap the server and the client library. Your events and channel callbacks stay the same.
Q: Is Laravel Reverb free? A: Yes. Reverb is an open-source package under the MIT license, so you only pay for the server it runs on. Pusher is the hosted alternative, where you pay them to run the WebSocket servers for you.
Q: Is Laravel Reverb production ready? A: Yes. It’s Laravel’s own package, and Laravel Cloud offers managed WebSocket clusters built on it. On your own server, raise the open file limit, keep the process running with a daemon and restart it on deploy. Forge’s Reverb toggle sets all of that up.
Q: Does Laravel Reverb need Redis?
A: Not on a single server. You only need a central Redis server to run Reverb across several servers, with REVERB_SCALING_ENABLED=true.
Q: Does @laravel/echo-vue have useEchoPrivate?
A: No. useEcho already handles private channels. This table lists the composables for other channel types.
Q: Why isn’t Laravel Echo receiving events?
A: Start with the queue worker, because ShouldBroadcast events go through the queue. If it’s running, look for the message in reverb:start --debug, then check whether the event name needs a leading dot. The troubleshooting section covers the errors you might see.
Q: Why does /broadcasting/auth return 403?
A: Auth worked, and your callback in routes/channels.php returned false, so check that the user should have access to that channel. A 401 means the token is missing or expired.
Q: What does “Application does not exist” mean in Reverb?
A: The app key in your frontend doesn’t match REVERB_APP_KEY on the server, and Reverb returns error code 4001. Fix VITE_REVERB_APP_KEY, then restart Vite.
Q: What is laravel-echo-server, and is it still maintained?
A: It’s a Node server that delivers Laravel broadcasts to Socket.io clients, and it’s no longer maintained. The GitHub repo is archived, and the last release, 1.6.3, came out in January 2022. The laravel-echo-server-updated fork hasn’t been updated since May 2022 either, so use Reverb.
Q: How do I start laravel-echo-server?
A: Install it with npm install -g laravel-echo-server, run laravel-echo-server init to create laravel-echo-server.json, then run laravel-echo-server start from the same folder. For anything new, use Reverb instead.