Deploy Web Server

Install Node Version Manager (nvm)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

Reload Profile

source ~/.bash_profile

Use nvm to install Node.js by entering the following into the command line.

nvm install 20

role

clone application code repository

git clone https://github.com/First-Cloud-Journey/000004-EC2.git

Go to the lab directory

cd 000004-EC2

View the directories in the web and Use npm init to initialize the project, which will create a sample package.json file.

ls
npm i

role1

Install pm2 in Global, PM2 is used to manage and monitor running Node.js applications. It allows applications to run in the background. Check the version

npm install -g pm2
pm2 --version

createpolicy

createpolicy

We redefine the script to run the application, we will use vim to open the pakage.json file, in the scripts section in the start key, assign it the following value, this will help our application run in the background:

pm2 start app.js

createpolicy

Continue using vim to enter the .env file, then enter the following content to establish a connection to the database.

DB_HOST='your db_host'
DB_NAME='awsfcjuser'
DB_USER='admin'
DB_PASS='password created in step 2.3'

createpolicy

Launch the application:

npm start
npm status

Check the Log to make sure the application is working properly

npm log

createpolicy

Next, we need to get the public DNS of the instance to be able to access the application from the browser.

createpolicy

The application is running

createpolicy

Next we use the pm2 startup command to configure PM2 to automatically restart applications when the server reboots. It will ask for the Startup Script setup, copy/paste that command and run it.

Run the pm2 save command to save the current state of the processes to the startup list.

createpolicy