Posted in

πŸ”§ Tutorial: How to Setup Socket.io in Sngine

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.

πŸ“Œ 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 “which php”


πŸ“Œ 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).

πŸ‘‰ Server Setup Needed

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

# 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;
}

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

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]

βœ… 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. Use Check Certificate (only available if not proxied).
  3. Open your site, login, and test chat in multiple tabs.

πŸ“Œ Summary

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

That’s it.

Happy Sngine πŸ™‚

Buy Sngine or Extend your support: https://bit.ly/BuySngine