Skip to content

Laravel Reverb ​

Laravel Reverb is Laravel's WebSocket server for real-time broadcasting. Reverb listens on a local port (8080 by default) and Nginx forwards the browsers' WebSocket connections to it over HTTPS. You can expose it in two ways:

  • Subdomain (recommended): browsers connect to wss://ws.domain.com. The simplest setup, no Nginx configuration to write.
  • Subpath: browsers connect to wss://domain.com/ws. No extra domain or SSL certificate needed.

Prerequisites ​

  • A Laravel website on FlashPanel with Reverb installed (php artisan install:broadcasting).
  • A server running Nginx.
  • SSL installed on the website browsers connect to (see SSL).

Step 1: Run Reverb in the background ​

Reverb must run continuously. On the server's Supervisor page, click Create and fill in:

  • Command: php artisan reverb:start
  • User: the Laravel website's user
  • Directory: the Laravel website's folder, for example /home/flashpanel/domain.com
  • Number Processes: 1

Click Save. Whenever you change the Reverb values in .env, restart this process so Reverb reads them again.

Step 2, option 1: Subdomain ​

  1. Create a website ws.domain.com (point its DNS to the server) with Proxy Port 8080, then install SSL for it. A website with a Proxy Port forwards all traffic to that port, WebSocket connections included, so no extra Nginx configuration is needed.

  2. Open the Laravel website's .env (the .env item in the Utilities group on its Overview page) and set:

    ini
    REVERB_APP_ID=123456
    REVERB_APP_KEY=your_app_key
    REVERB_APP_SECRET=your_app_secret
    REVERB_HOST="ws.domain.com"
    REVERB_PORT=443
    REVERB_SCHEME=https
    
    VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
    VITE_REVERB_HOST="${REVERB_HOST}"
    VITE_REVERB_PORT="${REVERB_PORT}"
    VITE_REVERB_SCHEME="${REVERB_SCHEME}"
  3. Rebuild the front end (npm run build) so the new VITE_ values are compiled in, then restart the Reverb process.

Step 2, option 2: Subpath ​

  1. In the Laravel website's .env, the application sends events to Reverb directly on the server, while browsers connect through your domain:

    ini
    REVERB_APP_ID=123456
    REVERB_APP_KEY=your_app_key
    REVERB_APP_SECRET=your_app_secret
    REVERB_HOST="127.0.0.1"
    REVERB_PORT=8080
    REVERB_SCHEME=http
    
    VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
    VITE_REVERB_HOST="domain.com"
    VITE_REVERB_PORT=443
    VITE_REVERB_SCHEME=https
  2. In the front-end Echo configuration (usually resources/js/echo.js), add the wsPath line:

    js
    window.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 ?? 80,
        wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
        wsPath: '/ws', // add this line
        forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
        enabledTransports: ['ws', 'wss'],
    });
  3. On the Laravel website's web server configuration page, click Add Custom Config (server), enter the block below, click Add Custom Config, then click Sync:

    nginx
    location /ws/app {
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass http://127.0.0.1:8080/app;
    }
  4. Rebuild the front end (npm run build), then restart the Reverb process.

Check the connection ​

Open the website, press F12, select the Network tab with the WS filter and reload the page. A connection to wss://ws.domain.com/app/... (or wss://domain.com/ws/app/...) with status 101 means Reverb is working. If it fails, check the Reverb process log on the Supervisor page.

Deployments

Add php artisan reverb:restart to the website's deployment script so Reverb loads the new code after each deployment.