Software Installs

How to Install Node.js on a cPanel VPS

Editor’s Note: As third-party software, ServInt does not support node.js beyond installation. Also, to follow these instructions, users must have a working knowledge of the command line. Click here if you would like more information about logging into your server on the command line.

Node.js is an application development software written in and for javascript for real-time event-driven applications, among other things. Installing node.js on a cPanel VPS is pretty straightforward. Let’s take a look.

The first thing that you will need to do is download the latest version from nodejs.org:

wget http://nodejs.org/dist/v0.10.32/node-v0.10.32.tar.gz

Before proceeding further, you will need to make sure that you meet the following requirements listed in the README file:

  1. GCC 4.2 or newer
  2. Python 2.6 or 2.7
  3. GNU Make 3.81 or newer

Update any software in the above list that is not up to date.

Once you make sure that you’ve met all of the requirements, unpack the node.js tarball and install it:

tar -xzvf node-v0.10.32.tar.gz
mv node-v0.10.32.tar.gz node
cd node
./configure
make && make install

Node.js is now installed. To test and make sure that it is working, you can create a basic server as a proof of concept. First, create a directory to store the apps in, you can call it “server”. Make the ownership all the same:

mkdir server
chown -R account:account /home/account/node
What's the difference between our Cloud VPS and our “Traditional” VPS? Find out more.
VPS

Then with your text editor of preference — I’m using vim in this example — create the file server.js. I used the code from the site nodebeginner.org since I am not proficient with javascript:

vim server/server.js
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8080);

Open the port in your firewall and then start things:

vim /etc/csf/csf.conf

Add the port, 8080, to the list of open ports

csf -r
screen
/usr/local/bin/node server/server.js
[ctrl d]
a

To test to see if it is working, go to port 8080 at your server’s main IP address: ip.add.re.ss:8080 You should get a message in your browser that says “Hello World”. If so, you have just confirmed that node.js is installed correctly.

Now we need to direct traffic for our domain to the node.js build. This can be done via the .htaccess file. Place the below lines into an .htaccess file in the public_html directory

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^(.*) "http\:\/\/127\.0\.0\.1\:8080\/$1" [P,L]

Your domain name replaces “domain” in the above example. When you visit your domain you should now see your node.js site.

Photo by Node.js

  • The New York Times
  • The Hill
  • Bloomberg
  • The Seattle Times
  • Computer World
  • Ars Technica
  • MSNBC