Apache - WHM

🚀 Laravel Reverb + Apache (cPanel/WHM) WebSocket Proxy Setup

This guide explains how to proxy Laravel Reverb WebSocket traffic through Apache when hosting on cPanel/WHM. By default, cPanel does not allow editing Apache <VirtualHost> directly, so we use userdata includes.

1. Enable required Apache modules

Make sure the following Apache modules are enabled in WHM → EasyApache 4 → Apache Modules:

  • mod_proxy

  • mod_proxy_http

  • mod_proxy_wstunnel

  • mod_rewrite

  • mod_headers

Verify via CLI:

httpd -M | egrep "proxy|rewrite|headers"

2. Create vhost include files

For the domain portal.example.com (replace with your domain), same with the username example_username (replace with the cpanel account username). First create the parent folder before creating the config files,

mkdir -p /etc/apache2/conf.d/userdata/std/2_4/example_username/portal.example.com/
mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/example_username/portal.example.com/

then create two include files:

nano /etc/apache2/conf.d/userdata/std/2_4/example_username/portal.example.com/websockets.conf
nano /etc/apache2/conf.d/userdata/ssl/2_4/example_username/portal.example.com/websockets.conf

3. Add WebSocket proxy rules

Paste this into both files:

<IfModule mod_proxy.c>
    ProxyPreserveHost On
    ProxyRequests Off

    # Proxy HTTP + WebSocket traffic for Laravel Reverb
    ProxyPass "/app"  "http://127.0.0.1:6001/app"
    ProxyPassReverse "/app" "http://127.0.0.1:6001/app"

    # Ensure WebSocket Upgrade works
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule ^/app/(.*) ws://127.0.0.1:6001/app/$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule ^/app/(.*) http://127.0.0.1:6001/app/$1 [P,L]

    # Forwarded headers
    RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}s"
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Port "443"

    # Optional CORS headers (adjust for your needs)
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "GET, POST, OPTIONS"
    Header always set Access-Control-Allow-Headers "Origin, Content-Type, Accept, X-Requested-With"
</IfModule>

4. Apply changes

Run:

/scripts/ensure_vhost_includes --all-users
/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd

Last updated

Was this helpful?