This guide explains how to integrate Laravel with Soketi using secure WebSocket (WSS) over SSL via Apache. The key is to proxy wss:// connections through Apache with SSL termination, while Soketi itself runs unencrypted on localhost.
-
Apache with mod_proxy, mod_proxy_http, mod_proxy_wstunnel, and mod_rewrite enabled.
-
Soketi server running and listening on port 6001.
-
Valid SSL certificate configured in Apache.
-
Soketi apps configured properly and Laravel broadcasting configured accordingly.
Make sure Soketi is installed:
npm install -g @soketi/soketiRun Soketi:
soketi start --config ./soketi.jsonEnsure it's listening on http://127.0.0.1:6001:
curl http://127.0.0.1:6001
# should return "OK"import Echo from 'laravel-echo';
import Pusher from 'pusher-js';
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: 'pusher',
key: import.meta.env.VITE_PUSHER_APP_KEY,
wsHost: import.meta.env.VITE_PUSHER_HOST,
wsPort: import.meta.env.VITE_PUSHER_PORT,
wssPort: import.meta.env.VITE_PUSHER_PORT,
cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
forceTLS: true,
encrypted: true,
disableStats: true,
enabledTransports: ['ws', 'wss'],
});PUSHER_HOST=app.test
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_ID="app-id"
PUSHER_APP_KEY="app-key"
PUSHER_APP_SECRET="app-secret"
PUSHER_APP_CLUSTER=eu
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"Add websocket.conf configuration file for Apache:
# Subdomain Also Supported
vi /etc/apache2/conf.d/userdata/ssl/2_4/username/domain.tld/websockets.conf
# Subdomain Also Supported
vi /etc/apache2/conf.d/userdata/ssl/2_4/username/subdomain.domain.tld/websockets.conf# Enable WebSocket proxying to Soketi on port 6001
ProxyPass "/app" "http://127.0.0.1:6001/app/"
ProxyPassReverse "/app" "http://127.0.0.1:6001/app/"
# Enable Events proxying to Soketi on port 6001
ProxyPass "/apps" "http://127.0.0.1:6001/apps/"
ProxyPassReverse "/apps" "http://127.0.0.1:6001/apps/"
#RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule ^/app/(.*) ws://127.0.0.1:6001/app/$1 [P,L]
RewriteRule ^/apps/(.*) ws://127.0.0.1:6001/apps/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule ^/app/(.*) http://127.0.0.1:6001/app/$1 [P,L]
RewriteRule ^/apps/(.*) http://127.0.0.1:6001/apps/$1 [P,L]
Restart Httpd/ Apache service Importantπ΄π΄π΄π΄
/scripts/rebuildhttpdconf && /scripts/restartsrv_httpdEnsure your browser trusts the local SSL certificate:
- Visit
https://app.test - If it shows "secure" (padlock icon), it's trusted
- If not, manually install the cert
Visit the site in browser and check DevTools Console/Network for:
wss://app.test/app/<key>?protocol=7&client=js&version=8.4.0
You can also test via:
npm install -g wscat
wscat --no-check -c "wss://app.test/app/YOUR_KEY"You now have secure WebSocket connections to Soketi over SSL using Apache as the reverse proxy. Laravel Echo should now work perfectly with real-time features.
- Always inspect DevTools > Network > WS tab
- Use
curl,wscat, andnetstat -an | find "6001"to confirm sockets - Double-check
ProxyPasspath: it must end with/appif you usewsPath: '/app'