Tutorial: How to Set Up Socket.io in Sngine

Status
Not open for further replies.
502591571_1215910113663716_4146382509682417071_n-1300x754.webp

Sngine supports real-time chat through Socket.io.

You can run the chat server in two modes:

  • Proxied (Recommended) → works on standard HTTPS port (443), no SSL cert needed inside Sngine.
  • Not Proxied → works directly on a custom port (e.g., 3000), requires SSL cert & key paths.

NOTE: Make sure you are running PHP 8.2 or 8.3 (8.4 not supported yet)

📌 Step 1 — Enable Socket.io
  1. Go to Admin Panel → Settings → Chat → Socket.io.
  2. Turn Chat Socket Enabled → ✅ ON.

📌 Step 2 — Select Socket Server

  • Choose PHP (default, works with PHPSocketIO bundled with Sngine, Node.js is coming soon and requires a Node server, not covered here).
  • For PHP Path you can get from your server admin or run this command in your server terminal.

Code:
which php

image-4-1024x471.webp

Admin-›-Chat-Settings-08-31-2025_02_06_PM-1024x495.webp

📌 Step 3 — Choose Proxy Mode

🔹 Option A: Proxied (Recommended)

In this mode, Apache or Nginx proxies WebSocket traffic to your chat server.

  • Toggle Chat Socket Proxied → ON.
  • Set Socket Port to 3000 (or whatever you run PHPSocketIO on).
  • Leave SSL Certificate Path and Key Path empty (not needed).

Admin-›-Chat-Settings-08-31-2025_02_11_PM.webp

👉 Server Setup Needed

If using Nginx, add to your vhost or nginx.cong file

NGINX:
# Socket.io
location /socket.io/ {
  proxy_pass https://localhost:3000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "Upgrade";
  proxy_set_header Host $host;
  proxy_read_timeout 86400s;
}

Like this

Screenshot-2025-08-31-at-2.11.24-PM.webp

If using Apache, add inside your <VirtualHost *:443>:

Apache config:
ProxyPass /socket.io http://localhost:3000/socket.io retry=0 timeout=30
ProxyPassReverse /socket.io http://localhost:3000/socket.io
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/socket.io/?(.*) ws://localhost:3000/socket.io/$1 [P,L]

WHM for example

Step 1. Enable Apache proxy modules

On WHM → EasyApache 4, make sure these are enabled:

mod_proxy

mod_proxy_http

mod_proxy_wstunnel

image.webp
image-1-768x185.webp
image-2.webp

Then Edit Apache VirtualHost for your website as showed above.

Or Go to the following path:

Home / Service Configuration / Apache Configuration / Include Editor

Apache config:
ProxyRequests Off
ProxyPreserveHost On

ProxyPass "/socket.io/" "http://127.0.0.1:3000/socket.io/"
ProxyPassReverse "/socket.io/" "http://127.0.0.1:3000/socket.io/"

RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/socket.io/(.*) ws://127.0.0.1:3000/socket.io/$1 [P,L]

Like this and restart your apache server:

image-3.webp

✅ In this mode, your site SSL (from cPanel/Let’s Encrypt) secures the connection.
❌ No certificate configuration needed in Sngine.

This mode is highly recommended, particularly if you are using Cloudflare, which only permits default ports 80 and 443 (SSL).

🔹 Option B: Not Proxied (Direct SSL on Socket Server)

In this mode, the chat server itself handles SSL.

  • Toggle Chat Socket Proxied → OFF.
  • Enter Socket Port → 3000 (or another free port).
  • Fill in:
  • SSL Certificate Path → e.g. /home/username/ssl/domain.com.crt
  • SSL Certificate Key Path → e.g. /home/username/ssl/domain.com.key
  • (Optional) Add CA bundle path if required.

    👉 You must download/export SSL certificate & private key from cPanel (under SSL/TLS → Certificates & Private Keys) and upload them into your hosting account (if not already available).

⚠️ Important: Many shared hosting providers block external ports like 3000. If your browser can’t connect, you must switch to proxied mode.

📌 Step 4 — Save and Test

  1. Click Save Changes.
  2. Then Click on Start button to check there is no previous
  3. Use Check Certificate (only available if not proxied).

image-5-768x114.webp

📌 Summary

  • If you’re on VPS or dedicated server → you can use either proxied or not-proxied.
  • If you’re on shared hosting (cPanel) →you can only use proxied (since non-standard ports are blocked).

    That’s it.
 
Status
Not open for further replies.

Donate: Campaign

Total amount
$0.00
Goal
$60.00

AdSense

Back
Top