Navigate back to the homepage

How to deploy nodejs application subdirectory level in apache ubuntu

Infinitbility
Node, Apache, Ubuntu
February 1st, 2021 · 1 min read
How to deploy nodejs application subdirectory level in apache ubuntu

Hello Friends,

Welcome To Infinitbility!

In this Article, we deploy nodejs application subdirectory level in apache ubuntu server. here you get complete tutorial to deploy, setup, and run node js project in apache server.

let’s start with subdirectory.

what is Subdirectory url level?

Some people also say sub url or custom url. subdirectory come after core domain.

Take below example.

suburl, subdir, subdirectory

here https://infinitbility.com is core domain & category is a subdirectory url.

Install Node

here we are installing node version 10. you can also on below curl command.

  • go to root dir on your ubuntu server.
1cd ~
  • download node nodesource setup using curl command.
1curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
  • run downloaded nodesource setup of node.
1sudo bash nodesource_setup.sh
  • install nodejs on your server.
1sudo apt-get install -y nodejs
  • check node version.
1node -v
  • check npm version.
1npm -v

Install pm2

Now we will install PM2, which is a process manager for Node.js applications. PM2 provides an easy way to manage and daemonize applications (run them as a service).

We will use Node Packaged Modules (NPM), which is basically a package manager for Node modules that installs with Node.js, to install PM2 on our app server. Use this command to install PM2:

1sudo npm install -g pm2

Install Apache2

  • install apache2 on your ubuntu machine.
1sudo apt-get install apache2

Next thing we need to proxy all requests incoming on port 80 through the URL of a node.js application to the running local node.js process. For this, we need to install/enable mod_proxy and mod_proxy_http modules on the Apache server :

1sudo a2enmod proxy
1sudo a2enmod proxy_http

Setup node project

put your node project code on html directory.

  • go to html directory.
1cd /var/www/html/

Assuming you guys know to put code on the ubuntu server. ( if not comment on the post we will definitely create a tutorial. )

setup virtual host

  • go to apache conf dir.
1cd /etc/apache2/sites-available/
  • you can also create a separate conf file for your project but here explaining with the default conf file.
1<VirtualHost *:80>
2 ServerAdmin [email protected]
3 ServerName example.com
4 ServerAlias www.example.com
5 DocumentRoot /var/www/html/example.com
6 <Directory />
7 Options -Indexes +FollowSymLinks
8 AllowOverride None
9 Require all granted
10 </Directory>
11
12 # subdirectory is your custom url
13 ProxyRequests On
14 ProxyPass /subdirectory http://example.com:8080
15
16
17 ErrorLog ${APACHE_LOG_DIR}/error.log
18 CustomLog ${APACHE_LOG_DIR}/access.log combined
19</VirtualHost>
  • enable sites ( when disable )
1sudo a2ensite 000-default.conf
  • restart your apache server
1sudo service apache2 restart

Run node project and check url

  • go to application folder and run below command
1pm2 start server.js

Similarly, we can configure multiple apps using separate ports. The idea is quite simple, we use different ports to configure multiple apps without having to change the original URL.

Looking to setup react aaplication to setup on apache serevr?.

check below link.

https://infinitbility.com/deploy-react-application-on-ubuntu-apache

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

More articles from Infinitbility

React Native Share

React Native Share

react native share example.

January 30th, 2021 · 1 min read
Image not showing in ios 14 react native

Image not showing in ios 14 react native

How to solve React Native show image issue in iOS 14

January 22nd, 2021 · 1 min read
© 2020–2021 Infinitbility
Disclaimer
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]