I am trying (!) to use laravel reverb in my local setup ( dockerized php-fpm nginx mysql )
but not matter what port or host I am keep getting
WebSocket connection to 'ws://127.0.0.1:8070/app/02f265e93304b96ba8d8?protocol=7&client=js&version=8.3.0&flash=false' failed:
which is bugging me since I am pretty sure about the env variables and tried EVERYTHING …
here are some of the assumptions you can have in my current situation :
1- Ran reverb:start inside the php-fpm container ( which I am not sure is the best way )
2- set env variables to correct values
3- Haven’t setup ssl certificates at all .
4- have echo.js pusher and broadcasting setup already .
Appreciate any thoughts.
2
Answers
Check that the port (8070) is exposed in your Docker configuration (docker-compose.yml) and mapped to the host. You might need something like:
services–>php-fpm–>ports–>8070:8070
Use localhost instead of 127.0.0.1 for WebSocket connections since 127.0.0.1 inside the container refers to the container itself.
Running reverb:start inside the PHP-FPM container might cause issues if it’s not properly mapped to external services or if the WebSocket server is trying to bind to 127.0.0.1. Consider running Reverb outside the container, or check the container logs to ensure there are no permission issues.
NGINX Reverse Proxy Configuration
Although you’re not using SSL, it’s worth noting that modern browsers may block non-secure WebSocket connections, especially in production environments. Consider setting up SSL when you move to production to avoid such issues.
PHP-FPM typically doesn’t serve WebSocket requests directly. Ensure that PHP-FPM is not interfering with the WebSocket server, and consider running the WebSocket server independently if possible.
Make sure the WebSocket server is running on a port that Docker has opened up, like port
6001 for Laravel WebSockets
.Then in your
.env
file set theBROADCAST_DRIVER
andPUSHER
and in your WebSocket
Else check in
config/broadcasting.php
the scheme is set to http since you are running in the local environment'scheme' => 'http',
Ensure that the WebSocket server and php-fpm can coexist in your Dockerfile, or add the WebSocket server as a separate service in your docker-compose.yml file: