Configure Real-Time Socket.io Applications on cPanel Hosting

Configure Real-Time Socket.io Applications on cPanel Hosting

Configure Real-Time Socket.io Applications on cPanel Hosting

Step-by-step guide to deploy and manage Socket.io-based real-time apps on cPanel hosting.

Introduction

Socket.io is a popular JavaScript library that enables real-time, bi-directional communication between clients and servers. Hosting real-time applications using Socket.io on cPanel requires special considerations due to shared hosting environments and limitations.

Prerequisites

  • Active cPanel hosting with Node.js support (e.g., Hiverift or similar providers)
  • Basic understanding of Node.js and Socket.io
  • Access to cPanel dashboard and File Manager or SSH access

Step 1: Setup Your Node.js Application with Socket.io

Create or update your Node.js app to include Socket.io. Here’s a simple example:

const express = require('express');
const http = require('http');
const socketIo = require('socket.io');

const app = express();
const server = http.createServer(app);
const io = socketIo(server);

io.on('connection', (socket) => {
  console.log('New client connected: ' + socket.id);

  socket.on('message', (msg) => {
    console.log('Message received: ', msg);
    io.emit('message', msg); // Broadcast to all clients
  });

  socket.on('disconnect', () => {
    console.log('Client disconnected: ' + socket.id);
  });
});

const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`);
});

Step 2: Upload Your Application Files

Use cPanel’s File Manager or FTP to upload your Node.js app files (including package.json, server.js, etc.) to a directory within your home folder.

Step 3: Install Dependencies

If your hosting allows SSH access, connect via SSH and run:

npm install

If SSH is unavailable, upload the node_modules folder from your local machine after running npm install.

Step 4: Configure Node.js Application in cPanel

  1. Log in to cPanel dashboard.
  2. Navigate to Setup Node.js App.
  3. Create a new application or select your existing one.
  4. Set the Application Root to your app directory.
  5. Set the Application Startup File to your main file (e.g., server.js).
  6. Select the Node.js version supported by your app.
  7. Click Create or Update.

Step 5: Handle WebSocket Connections Behind Proxy

cPanel hosting typically uses Apache or NGINX as a proxy server. You must ensure WebSocket upgrade headers are properly forwarded.

If you have access to your domain’s .htaccess file, add the following to enable WebSocket proxying:

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:3000/$1 [P,L]

RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://localhost:3000/$1 [P,L]

Note: Replace 3000 with your actual Node.js port if different.

Step 6: Restart Your Application

Use the Setup Node.js App interface in cPanel to restart your application so changes take effect.

Step 7: Test Your Real-Time Application

Open your application URL in multiple browsers or devices and test real-time features (e.g., chat messages) to verify Socket.io is working correctly.

Tip: Use browser developer tools (Console and Network tabs) to debug WebSocket connections and check for errors.

Troubleshooting

  • Connection Issues: Verify WebSocket support and proxy rules in .htaccess.
  • Port Conflicts: Ensure no other app is using the same port as your Node.js app.
  • Resource Limits: Some shared hosting environments have limits on concurrent connections or long-running processes. Consider upgrading to VPS if needed.

Additional Resources

Need Support?

Contact Hiverift’s development support team at dev@hiverift.com for assistance deploying Socket.io apps on cPanel hosting.

© 2025 Hiverift. All rights reserved.

Post Your Comment

Build Your Website with HiveRift

From professional business to enterprise, we’ve got you covered!

©2025, Hosting. All Rights Reserved by GutenKit

HiveRift
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.