Yes, you can run multiple Laravel Reverb instances on a single Forge server, but you need to ensure that each instance uses a different port and has its own configuration. By default, Reverb listens on port 8080, so if you have multiple sites, their Reverb instances will conflict unless you change the ports.
Here's how you can set it up:
-
Configure Different Ports for Each Site
In each site's
.envfile, set a unique port for Reverb:REVERB_PORT=8081 # For staging REVERB_PORT=8082 # For productionMake sure these ports are open in your server's firewall.
-
Update Broadcasting Configuration
In
config/broadcasting.php, ensure thereverbconnection uses the environment variable:'connections' => [ 'reverb' => [ 'driver' => 'reverb', 'host' => env('REVERB_HOST', '127.0.0.1'), 'port' => env('REVERB_PORT', 8080), ], ], -
Update Your Frontend
When connecting to Reverb from your frontend (e.g., with Laravel Echo), specify the correct port:
window.Echo = new Echo({ broadcaster: 'reverb', host: window.location.hostname + ':8081' // or ':8082' for production }); -
Start Reverb for Each Site
SSH into your server, navigate to each site's directory, and start Reverb with the correct environment:
php artisan reverb:startOr, if you're using Supervisor, ensure each site's Supervisor config uses the correct path and environment.
-
Supervisor Example
Example Supervisor config for staging (
/etc/supervisor/conf.d/staging-reverb.conf):[program:staging-reverb] process_name=%(program_name)s command=php /home/forge/staging.yoursite.com/artisan reverb:start autostart=true autorestart=true user=forge redirect_stderr=true stdout_logfile=/home/forge/staging.yoursite.com/storage/logs/reverb.log environment=REVERB_PORT="8081",APP_ENV="staging"And similarly for production, but with a different port and path.
Summary:
Yes, it's possible to run multiple Reverb instances on a single Forge server. Just ensure each site uses a different port and the correct environment variables. This setup is similar to running multiple queue workers or websockets servers for different sites on the same machine.
Let me know if you need a sample Supervisor config or more details!