I am working on a website which is an online game using Laravel 11 with View 3 and Reverb (SPA without SSR for now). On the localhost the websockets work, but when I uploaded it to the production server with Apache they don’t work.
On localhost in .env I have
REVERB_HOST="localhost"
REVERB_PORT=8080
REVERB_SCHEME=http
In production I change them to
REVERB_HOST="www.mydomain.com"
REVERB_PORT=443
REVERB_SCHEME=https
Also in the virtual host file I add
<VirtualHost 192.168.100.12:443>
...
SSLEngine On
ProxyPass "/app" "ws://0.0.0.0:8080/app"
ProxyPassReverse "/app" "ws://0.0.0.0:8080/app"
</VirtualHost>
After these settings in the browser tab for Network / websockets I now get that there is a connection established
{"event":"pusher:connection_established","data":"{"socket_id":"325487270.879942365","activity_timeout":30}"}
{"event":"pusher:subscribe","data":{"auth":"yzvrte6lfsudidxcfwkg:4055a502db436191e71198aeadf394db1defd0850c86e55f37fde6d59a9e83eb","channel":"private-user.3"}}
{"event":"pusher_internal:subscription_succeeded","data":"{}","channel":"private-user.3"}
As well as pinging periodically. But when the server tries to send data through the websocket I get the error
The POST method is not supported for route apps/174502/events. Supported methods: GET, HEAD.
This route is located in /vendor/laravel/reverb/src/Servers/Reverb/Factory.php
protected static function pusherRoutes(): RouteCollection
{
$routes = new RouteCollection;
...
$routes->add('events', Route::post('/apps/{appId}/events', new EventsController));
return $routes;
}
Why is it giving me this error? I might be doing something wrong in the configuration. Does anyone have any idea how to properly configure Reverb for Apache?
2
Answers
After struggling with this for almost 2 days, I have finally managed to get Reverb working on AWS LAMP server in production.
You need to add a few more things to your .env file
That is all, you don’t need to setup reverse proxy or open any port.
For me the correct/required Apache config was/is:
Note that as per documentation Reverb uses two different endpoints, /app handles websocket connections and /apps handles api requests.