Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I handle port conflicts when setting up Laravel Reverb on a production server
    Laravel Reverb port conflicts Nginx configuration SSL/TLS Laravel Echo Laravel setup production server WebSocket handling


How do I handle port conflicts when setting up Laravel Reverb on a production server


here are the steps to handle port conflicts when setting up Laravel Reverb on a production server:

Configuring Nginx for Laravel Reverb

1. Set up a subdomain: Create a subdomain (e.g., `reverb.example.com`) that will be used to access your Reverb server. This helps avoid port conflicts with other services running on the same server.

2. Configure Nginx proxy settings: Update your Nginx configuration to proxy requests from the Reverb subdomain to the Reverb server's IP and port. Assuming the Reverb server's default IP is `0.0.0.0` and port is `8080`, configure the proxy settings to forward requests from `reverb.example.com` to `0.0.0.0:8080`.

3. Handle WebSocket connections: Add a location block for the `/ws/` path in your Nginx configuration to handle WebSocket connections. Proxy these requests to the Reverb server running on `127.0.0.1:8080`.

4. Enable SSL/TLS: Ensure that the Nginx configuration includes the necessary SSL/TLS settings, such as the SSL certificate and key paths, to enable HTTPS for the Reverb WebSocket connections.

Configuring Laravel Echo

5. Update Laravel Echo configuration: In your Laravel application, update the Laravel Echo configuration to use the newly created subdomain `reverb.example.com` and the default HTTP port `80`.

Configuring Laravel Application

6. Specify Reverb host and port: In your Laravel application's configuration file (`.env`), set the `REVERB_HOST` to `localhost` and the `REVERB_PORT` to `8080`.

Running the Reverb Server

7. Start the Reverb server: Use the `reverb:start` Artisan command to start the Reverb server. You can optionally specify a custom host and port using the `--host` and `--port` options.


   php artisan reverb:start --host=0.0.0.0 --port=8080
   

Alternatively, you can define the `REVERB_SERVER_HOST` and `REVERB_SERVER_PORT` environment variables in your application's `.env` file.

By following these steps, you should be able to successfully integrate Laravel Reverb with your production server and avoid port conflicts with other services running on the same machine.

Citations:
[1] https://discuss.dgraph.io/t/resolving-port-conflicts/4703
[2] https://github.com/laravel/framework/discussions/50625
[3] https://github.com/laravel/reverb/issues/107
[4] https://github.com/laravel/framework/discussions/50675
[5] https://stackoverflow.com/questions/78383337/solution-laravel-reverb-does-not-work-in-production-with-apache