DEV Community

Shreya Princy
Shreya Princy

Posted on

Create a simple EC2 instance and run a webserver and access it from outside.

Step 1: Launch Your Virtual Server ,log into your AWS Management Console.

Search for EC2 in the top search bar and click on it.

Give your server a name, like "My-First-Web-Server".

Step 2:Under Application and OS Images (Amazon Machine Image), select Amazon Linux. It is optimized for AWS.

Ensure the Free tier eligible tag is visible so you don't accidentally run up a bill.

For the Instance type, leave it as t2.micro (or t3.micro depending on your region).

Step 3: Create the Keys to the instance.
To securely connect to your server later, you need a digital key.

Under Key pair (login), click Create new key pair.

Name it something like "web-server-key", leave the defaults , and hit create.

Step 4: Configure the Security Groups
By default, AWS blocks all incoming traffic to protect your server. Since we are building a web server, we need to open the doors for the internet to see it.

Under Network settings, check the box that says Allow SSH traffic from . Set the dropdown to My IP for maximum security.

next step: Check the box for Allow HTTP traffic from the internet. This opens Port 80, which is the universal channel for web browsers to access your site.

Step 5: Launch and Connect
Hit the orange Launch instance button on the right side of your screen.

Once it says "Success", click on the instance ID to go to your instances page. Wait until the "Instance state" says Running.

Select your instance, and click the Connect button at the top.

navigate to the EC2 Instance Connect tab and hit Connect. A black terminal window will pop up in your browser. You are now inside your server.

Step 6: Install the Web Server
Now that we are inside the machine, we need to install the software that serves web pages . Copy and paste these commands into your terminal one by one, hitting Enter after each, Update the system, Let's make sure our software is up to date.

Install Apache: This is the actual web server software.

Start the server: Turn the engine on.

Keep it on: Tell the server to start automatically if the machine ever reboots.

Step 7:It is time to see the work.

Go back to your EC2 dashboard where your instance details are.

Find the Public IPv4 address like 3.85.22.112.

Copy that address, open a new tab in your web browser, paste it in, and hit enter.
You have officially launched a server in the cloud and made it accessible to the entire world.

"Terminate instance" to destroy it and stop any potential future billing.

Top comments (0)