Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daominhsangvn/b1f1a48e053b2694c9fb297379dcd84c to your computer and use it in GitHub Desktop.
Save daominhsangvn/b1f1a48e053b2694c9fb297379dcd84c to your computer and use it in GitHub Desktop.
How to deploy front-end (AngularJS, Angular, ReactJS...) and nodejs to AWS EC2 Linux

How to deploy front-end (AngularJS, Angular, ReactJS...) and nodejs to AWS EC2 Linux

Preparation

  • PEM file containing private key from AWS server.
  • A domain to server
  • GIT Bash (In Window, can't use command line tool or powershell).

Steps:

Step 1: Connect to server:

  • In Window, open GIT Bash and run: $ ssh -i <path-to-pem-file> <root/ubuntu/ec2-user/centos>@<server domain>
  • For example $ ssh -i pemfile.pem [email protected]

Reference Link

Connect is success in case your commandline changed to your remote server machine ip and name.

Step 2: Installing Stubs:

We need

  • node for environment.
  • npm for installing packages from your project.
  • git for version controlling (or pull push).
  • unzip for unzip compressed files (*.zip).
  • http-server for running server.
Step 2.1 Install NodeJS Latest version

Running following command in order

  • Delete old nodejs: $ sudo apt-get purge nodejs npm
  • Add nodejs 6 source: $ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
  • Install nodejs: $ sudo apt-get install -y nodejs
  • To use node command: $ sudo ln -s /usr/bin/nodejs /usr/bin/node
Step 2.2 Install npm, git, unzip

Run commands:

$ sudo apt-get install git

$ sudo apt-get install npm

$ sudo apt-get install unzip

$ npm i http-server -g

Step 3: Upload local file

Step 3.1: Create a new folder to contain our project files
Step 3.2: zip whole current project in your local machine
Step 3.3: We run: $ scp -i <path-to-pem-file> <path-to-zip-file> <root/ubuntu/ec2-user/centos>@<server domain>:<folder-name-in-server>
Step 3.4: Unzip file on server using command: unzip <path-to-zip-file>.

Step 4: Install and run

Step 4.1: Go to folder of code, run npm install to install packages.
Step 4.2: Run http-server -p 80

Keep that running and enjoy by going to domain and check. ☺️

Reference Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment