Host a static website on AWS EC2

Host a static website on AWS EC2

To get started with this signup for an AWS account. I will guide you step by step to host your website on AWS EC2.

Step 1 - Launch an EC2 instance

  1. Search for EC2 and select EC2.

image.png

2. Click on Launch instance

image.png

3. Enter the details

  • Enter your machine name

image.png

  • Select Amazon Linux as your operating system

image.png

  • select instance type as t2.micro
  • In key pair login you can proceed without a key pair

image.png

  • In network settings select to create a security group in this check all 3 boxes.

image.png

  • Let storage be 8GB no need to change this

image.png

4. Click on the Launch instance

Step 2 - Connect to your EC2

In your EC2 Dashboard go to Instances(running), It should be looking like this

image.png

Select your machine and click on the connect

CONNECT.png

Go to EC2 Instance Connect and click on connect

image.png

Once you connect you will see something similar to this

image.png

Update your machine and download the httpd server

sudo yum update -y
sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd

Next change your directory to /var/www/html

cd /var/www/html

Go back to the parent directory www and enter the following command this gives the ec2-user to create files inside the html directory

cd ..
sudo chown ec2-user html

move to html directory and create a file here using the touch command

cd html
touch index.html

Now use

vi index.html

to edit the index.html. Press i(for insert) and paste this there

<!DOCTYPE html>
<html lang="en">
    <style>
        .center {
  margin: auto;
  width: 50%;
  border: 3px solid green;
  padding: 10px;
}
    </style>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AWS EC2 WEBSERVER</title>
</head>
<body class="center" style="border-radius: 20;">
    <h1>Hello World</h1>
</body>
</html>

and press escape and type ":wq" to save and exit.

Step-3 Final Step

Go to your instances and select the public IPv4 DNS

image.png

and in the URL edit it to use HTTP protocol instead of HTTPS as we don't have an SSL certificate.

Congratulations your website is hosted on to your EC2 instance running on port 80

image.png

Thank you for following me, Do reach out if you need help running your own web server.

Did you find this article valuable?

Support Shrikar Kulkarni by becoming a sponsor. Any amount is appreciated!