In this post, we will guide you through the process of creating an instance on Amazon EC2, configuring it with an Ubuntu server, and installing various essential components like NGINX, MySQL, Node.js, Git, Docker, and SSL certificates. By following these step-by-step instructions, you’ll be able to set up a robust web server environment for hosting your applications. Let’s dive in and get started!
CREATING INSTANCE
- Move to EC2
- Click on Launch instances
- Select free tier ubuntu server / any other as required
- Storage change to 30G
- Review and Launch
- Then download pem file
INSTALLING NGINX
- Login to server with pem file
- Make sure your pc is update:
sudo apt update
- install nginx
sudo apt install nginx -y
- Adjust firewall
sudo ufw app list
=> will list the application profiles - Make sure to allow http from security groups.
- Add HTTP to be allowed.
sudo ufw allow 'Nginx HTTP'
(IF NEEDED DO THAT FOR HTTPS AS WELL)
- Add HTTP to be allowed.
- Now get your public url
curl -4 icanhazip.com
- Now hit the given url and you should be able to see welcome to nginx screen
MYSQL
- Install mysql server
sudo apt install mysql-server
- Configuring mysql
sudo mysql_secure_installation
- Agree terms ‘Y’
SELECT PASSWORD LEVEL => 1 (medium) (p@ssw0rd)
- Accept the changes as given
- Now login to mysql with sudo as previosuly given password won’t work
sudo mysql
- Create user
CREATE USER 'trackify'@'localhost' IDENTIFIED BY 'p@ssw0rd';
- Grant all privileges:
GRANT ALL PRIVILEGE ON *.* TO trackify@localhost;
- Flush privileges:
FLUSH PRIVILEGES;
NODE JS
- Install node using NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm list-remote
nvm install
v16 (lts will automatically be installed)
GIT
git -v
sudo apt install git
if not found
DOCKER
-
sudo apt install apt-transport-https ca-certificates curl software-properties-common
-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
-
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
-
apt-cache policy docker-ce
-
sudo apt install docker-ce
-
sudo systemctl status docker
REMOVE SUDO ON DOCKER
sudo usermod -aG docker $USER
NOW LOGOUT AND LOG BACK IN (exit and connect to server)
-
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
-
sudo chmod +x /usr/local/bin/docker-compose
ADD YARN:
-
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
-
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
-
sudo apt update
-
sudo apt install yarn
REACT Deployment: (NGINX)
location / {
try_files $uri /index.html;
}
ADDING SSL:
sudo apt install certbot python3-certbot-nginx
Install certbot
sudo certbot --nginx -d example.com -d www.example.com