Installing & Running WebSocket (Laravel Reverb) for Chat Realtime

Installing & Running #

Laravel Reverb is officially supported starting from:

PackageMinimum VersionNotes
Laravel Frameworkv11.30+Reverb ships as an official package since Laravel 11.30
PHP8.2+Required by Laravel 11

Install Reverb

composer require laravel/reverb
php artisan reverb:install

This installs:

  • config/reverb.php
  • routes/channels.php
  • Broadcasting setup
  • Optionally a ready Supervisor config template

Configure Reverb (Port, Host)

Default Reverb server runs at:

  • Host: 0.0.0.0
  • Port: 8080

You can change it in .env:

REVERB_HOST=0.0.0.0
REVERB_PORT=6001

And ensure config/reverb.php uses .env values:

'host' => env('REVERB_HOST', '0.0.0.0'),
'port' => env('REVERB_PORT', 8080),

Start the Reverb WebSocket Server

Run manually:

php artisan reverb:start

You should now see:

Reverb server running on ws://0.0.0.0:6001

Run Reverb as a Background Service (Supervisor)

Edit or create /etc/supervisor/conf.d/reverb.conf

[program:reverb]
command=/usr/bin/php /var/www/yourapp/artisan reverb:start
directory=/var/www/yourapp
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/reverb.log
user=www-data

Apply:

supervisorctl reload
supervisorctl update
supervisorctl restart reverb

Apache Proxy Configure #

Enable Modules:

a2enmod proxy
a2enmod proxy_http
a2enmod proxy_wstunnel
systemctl restart apache2

VHOST file (/etc/apache2/sites-available/reverb.conf):

<VirtualHost *:80>
    ServerName pusher.shaunsocial.com
    #change pusher.shaunsocial.com to your domain
    ProxyPreserveHost On

    # WebSocket (Reverb)
    ProxyPass "/"  "ws://127.0.0.1:6001/"
    ProxyPassReverse "/"  "ws://127.0.0.1:6001/"

    ErrorLog ${APACHE_LOG_DIR}/reverb_error.log
    CustomLog ${APACHE_LOG_DIR}/reverb_access.log combined
</VirtualHost>

Nginx Proxy Configure #

If you are not using apache, you can use nginx.

create /etc/nginx/sites-available/reverb.conf

server {
    listen 80;
    server_name pusher.shaunsocial.com;
    #change pusher.shaunsocial.com to your domain
    
    # if you use HTTPS (recommend)
    # listen 443 ssl http2;
    # ssl_certificate /etc/letsencrypt/live/pusher.example.com/fullchain.pem;
    # ssl_certificate_key /etc/letsencrypt/live/pusher.example.com/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:6001;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_read_timeout 60s;
        proxy_send_timeout 60s;
    }
}

ShaunSocial Configure #

Go to Admin Dashboard -> General Configuration

Powered by BetterDocs