Set Up a Node js App for a Website With Apache on Ubuntu

Set Up a Node js App for a Website With Apache on Ubuntu

Node.js is a JavaScript runtime environment which lets you easily build server-side applications. This post will explain how to set up a Cloud Server running Ubuntu 16.04 so that Node.js scripts run as a service, and configure the Apache server to make the script accessible from the web.

Install Node.js

Update your server’s packages and install curl with the following commands:

sudo apt-get update
sudo apt-get install curl

Download the Node.js PPA:
curl -sL -o

Run the command to add the PPA to your server’s package cache:

sudo bash

Note: This script will update the server automatically. There is no need to run apt-get update a second time.

Install Node.js:
sudo apt-get install nodejs

This will automatically install npm as well.

Finally, install the build-essential package for npm:
sudo apt-get install build-essential

After install configure Apache

To access the Node.js script from the web, install the Apache modules proxy and proxy_http with the commands:
sudo a2enmod proxy
sudo a2enmod proxy_http
Once the installation is complete, restart Apache for the changes to take effect:
sudo service apache2 restart
Edit this file with your editor of choice, for example with the command:
sudo nano /etc/apache2/sites-available/

<VirtualHost *:80>

   ProxyRequests Off
   ProxyPreserveHost On
   ProxyVia Full
   <Proxy *>
      Require all granted

   <Location /nodejs>

    <Directory "/var/www/">
    AllowOverride All

sudo services apache2 restart

Lets Get Started your project with professional way

Get in touch and let us know
how we can Help

Contact Us