Deploying a Nodejs Application on Cyberpanel with Openlitespeed is a seamless process that can be achieved following the steps below.
In this guide, I’ll be using Nodejs version 18, Almalinux version 8 and sub-domain
Steps #
Step 1 : Install Nodejs on Your server. #
Install curl #
Before you begin, ensure that curl is installed on your system. If curl is not installed, you can install it using the following command:
sudo yum install -y curl

Visit Here to See nodejs versions you can easily install depending on your operating system
https://github.com/nodesource/distributions
Download the setup script for your preferred nodejs version. I’ll be using 18 in this example. #
curl -fsSL https://rpm.nodesource.com/setup_18.x -o nodesource_setup.sh

Run the setup script as root: #
bash nodesource_setup.sh
You will see below output

Install Nodejs #
dnf -y install nodejs

Confirm node is installed
node -v
#

Step 2: Create a website on cyberpanel and upload your files to the public_html folder. #
Once extracted, ensure to move your files to the public_html folder.


Next, navigate to the website path via SSH and run npm install

npm install

Step 3 : Add Application Context. #
Go back to Cyberpanel dashboard > Websites > List Website > Manage > Configurations >vHost and Add the context below to vHost section.
Add Context below and edit as needed.
NOTE: DO NOT delete existing context, only scroll down to the bottom and add the new one.
The context tells OpenLitespeed to server our Nodejs app. Without the Context, it will server other normal php or html based sites without an issue.
context / {
type appserver
location /home/supernode.lintsawa.com/public_html
binPath /usr/bin/node
appType node
maxConns 100
rewrite {
}
addDefaultCharset off
}
All Done.
Restart Openlitespeed.
/usr/local/lsws/bin/lswsctrl restart

Reload your site and it should be working well.

Step 4: Troubleshooting (Optional) #
In case of Any Errors, use the command below to troubleshoot and Fix them.
tail -f /usr/local/lsws/logs/stderr.log
Congrats. You’ve successfully hosted your Nodejs app on Cyberpanel.
Happy Hosting!