In this article, we explain the best way to activate cPanel’s Application Manager plus how to install, register, and manage Node. js applications.
Getting Started With the cPanel Application Manager
cPanel users may register Node. js applications and associate them with a domain name in Application Manager . To offer this particular feature to hosting users, server administrators should first install the handful of support packages plus ensure that Application Manager is turned on.
We’ll use WHM’s Function Manager to change on Application Manager . Open Feature Manager, which is under Deals in the WHM sidebar menu.
Click on the Edit button below Manage Feature Listing using the Default list chosen in the dropdown menu.
Enter Application Manager in the search field, and verify that its access in the feature list is checked. If it isn’t, click the adjacent box and after that Save at the bottom of the page.
Next, we’ll install the particular software that allows cPanel in order to run and manage Node. js applications, including the mod_passenger app server and EasyApache4’s Node atmosphere. You will need to log in as underlying with SSH to install the particular software:
yum install ea-ruby24-mod_passenger ea-apache24-mod_env ea-nodejs10
Application Manager is now available within user cPanel accounts and ready to host Node. js programs.
Creating a credit card applicatoin in the particular cPanel Application Manager
Hosting applications with cPanel is a two-step process:
- Install the app to the server.
- Sign-up it with Application Manager .
We’ll look on registering an application in the particular next section, but first we have to install it on the machine. Users of the Git™ version manage system could clone a database with its command-line client or even cPanel’s Git Version Control interface. Nevertheless, to illustrate the procedure, we’ll produce a simple single-file application.
Sign in with SSH as a cPanel consumer and create a new directory in their home directory.
You can call the directory anything you want. This particular is where your app’s program code files will live. Create a file called app. js in this particular directory with your preferred text editor. cPanel expects the application’s entry point to be called app. js , so it’s best to stay with the standard naming tradition unless you have a great reason to improve it .
Paste the following code and conserve the new file.
const http = require('http')
const hostname = '127. 0. 0. 1';
const port = 3000; const server = http. createServer((req, res) => res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World! I am your new NodeJS app! n');
); server. listen(port, hostname, () => console.log(`Server running at http://$hostname: dollar port /`);
The code sets up an HTTP machine on port 3000. It responds to web requests with the message: “Hello World! I am your NodeJS app! ”
We can go straight to the sign up step, but let’s make certain the app works first. Run the following command, which executes our mini-app with EasyApache’s Client. js installation.
/opt/cpanel/ea-nodejs10/bin/node application. js
All being well, you will see a message that says:
Machine running at http://127.0.0.1:3000
Finally, open up a brand new terminal window and sign in to your server as the particular same cPanel user. We’ll use the curl HTTP client to send the particular app a request.
If it responds along with “’Hello World! I am the NodeJS app on cPanel, ” you can move on to the next stage: registering your Client. js app with cPanel.
Registering Your Node. JS Software in the cPanel Application Supervisor
Registering tells the Passenger application manager and cPanel where to find the application and which website you would like to use.
In cPanel, open the Application Manager, which you’ll find under Software for the main page.
Click the Register Application button.
Within the Application Settings table, we need to provide four pieces associated with information:
- Application Name: A display name for that application. You can choose any name, but it must start with a number or letter, and it can’t contain intervals.
- Deployment Domain: The app’s website name. The domain must already be associated with the cPanel account.
- Base Application URL: The particular app’s homepage will be available at the deployment domain + the base WEB LINK. For example, in the event that the Deployment Domain name is “example. com” and you enter “nodeapp” within this field, the app can be served from “example. com/nodeapp. ” The URL extension does not be the same as the directory that stores the app’s files.
- Application Path: The particular location of the app’s data files relative to the user’s house. In our example, we created a directory in home called “nodejsapp, ” so we’d get into “nodejsapp” here.
The Deployment Environment selector indicates if the app is under development or ready for deployment in a production environment.
Beneath the Application Construction table is an interface for configuring environment factors. We’ll look at them in greater depth in the following section.
For now, we’ll click on the Deploy button at the bottom associated with the page, and cPanel can configure the app’s environment and domain. Once it’s finished, a person can open your new app in a web browser on the URL you simply configured: “example. com/nodeapp” in our examples.
Unlike a real app, our one-pager has no external dependencies. In the event that it did, cPanel Application Manager would certainly display the Assure Dependencies button to get one-click installation. The button is only available for apps along with a package. json file that listings dependencies.
If you’re subsequent our examples and would like to see Guarantee Dependencies in action, add a file called package, json to the app’s directory with the following contents:
"name": "nodejsapp", "version": "1.0.0", "description": "A Node App", "main": "app.js", "author": "", "license": "ISC", "dependencies": "express": "^4.17.1"
Because you can see, we have got listed the Express web construction as a dependency. The Ensure Dependencies button should now be obtainable in Application Manager. Once you click it , cPanel installs Express and any applications and libraries it depends on.
Adding Environment Variables to Your Node. JS App’s Environment
Environment variables are name-value pairs that shop a chunk of information. These people work much like variables in programming, except that they are not internal towards the program but part of its external environment. Servers use environment factors to hold useful configuration information.
For example, CentOS uses the particular PATH environment variable to store a list of directories that contain command-line programs. When you enter a command like “ls, ” the shell looks through those directories for an executable file with this name. When there was no PATH adjustable, you’d have to enter the complete path of every command: “/usr/bin/ls” instead of just “ls. ”
The server administrator can modify the PATH environment variable, controlling the directories the shell appears in without modifying its inner code. With cPanel’s Application Manager, you can add environment factors to your Node. js app’s atmosphere to configure its behavior within the same way.
const port sama dengan 3000;
In reality, a programmer is unlikely to know the correct port whenever they write the code. To provide users a lot more flexibility, they could tell the app to look in the environment for a variable called PORT and to use its value when creating the app.
const INTERFACE = process. env. PORT || 3000;
This sets the app’s internal PORT variable to the particular value of the environment adjustable called PORT or to a default of 3000 if a good environment variable isn’t set.
At this point the user will be able to tell the application which port to bind in order to by setting a PORT variable in the app’s environment. To do this in cPanel’s Application Manager, get the Environment Variables interface beneath Application Configuration and click Add Variable.
Enter a variable title and value, and click Save.
Modifying Your Node. JS Application
A person can edit a Node application’s registration configuration in the Application Manager.
Click the Edit link in the Actions column. In this particular interface, you can edit all of the values you set when first registering your application, including the particular environment variables.
Uninstalling Your own Node. JS Application
To do away with or “unregister ”a Node. js application from cPanel, click the unregister link at the right of the particular Application Manager table.
When you unregister an application, cPanel removes this from the list, deletes its configuration file, and dissociates it from the domain. cPanel does not delete the application’s files, however, you are free to delete them yourself in File Manager or upon the command line.
Provide Node. JS Hosting to Your own cPanel Server
Since always, if you have any feedback or comments, please let us know. We are here to help in the best ways all of us can. You’ll find us upon Discord, the cPanel forums, and Reddit.