Setting up an Apache Web Server on AWS

Setting up an Apache Web Server on AWS

Hey there! Here's how you can quickly set up a web server on AWS.

Requirement:

  • An AWS Account (preferably Free Tier so that you are not charged for using cloud infrastructure)

Opening up the EC2 Console in AWS

image.png

When you log in to AWS, you are greeted with this dashboard. You can simply open up the search bar on top and search for EC2.

image.png

Click on the first result and you'll be in the EC2 Dashboard.

Creating a new EC2 Instance

image.png

Click on the Launch Instance button to create a new EC2 Instance.

image.png

In Step 1, you get to choose a template for your machine, which has its OS, certain pre-installed applications, etc. and it is AWS terminologies, it is called an AMI.

For now, we can choose Amazon Linux as our AMI, but we can also go ahead and choose Ubuntu 20.04 as an AMI since both are Linux machines anyway.

image.png

There are various instance families to choose from, with different hardware configurations which result in better or worse performance.

We'll proceed with t2.micro, which is the instance family by default since it is a part of the Free Tier.

Click on Configure Instance Details in the bottom-right to proceed. You can leave Instance Details, Storage (step 4) and Tags (step 5) as default and proceed to Step 6.

image.png

image.png

image.png Optionally, you can add a tag as an identification for your instance.

image.png

Under the Security group, you can create a new Security Group which allows all inbound sources via HTTP and SSH (not always recommended). Click on Review and Launch and again, click on Launch.

image.png

On prompt, choose to create a new Key Pair and name it. Then, download the file and then click on Launch Instances. Keep the file safe, we'll need it for remote access.

image.png Your instance is now created and it is about to start.

Connecting to an EC2 Instance

image.png

Once the Instance State shows "Running", we can connect remotely to the EC2 instance. Copy the Public IPv4 Address of your instance from Instance Details.

Open up the terminal as admin and change the directory to the folder where you have kept the .pem file, the Downloads folder in my case. Then use the ssh command with your key file with username ec2-user and the public IP address.

cd Downloads
ssh -i my_key_file.pem ec2-user@00.11.22.33

image.png You'll be asked to verify the fingerprint. Simply type yes.

image.png Once that's done, you'll be having remote access to the Ec2 instance :)

We can now install the apache daemon on this machine and start the server on this machine.

Installing Apache and Starting the Server

Run these commands to update your package dependencies and install httpd (Apache Daemon). Then, we can start the httpd server.

sudo su
yum update -y
yum install httpd -y
service httpd start

image.png

Once the service has started, go back to the console and again, copy the public IPv4 address. Create a new Tab on your browser and paste this address.

image.png

If you see this page, your web server is up and running!

image.png

It is good practice to clean up/delete/terminate all services you have used on AWS (on any Cloud really) so that you are not charged in the future.

Back in the Ec2 console, right-click on your instance and choose Terminate. This will terminate your EC2 instance and the storage which was associated with it.


This way, you can also set up servers like MySQL or Postgres and share databases with your teammates as long as the server is running so that you can work together. Cloud has definitely made collaboration a lot simpler than it previously was.

If you did read it all until here, I appreciate it and I hope it helped. Cheers :)

Did you find this article valuable?

Support Sreekesh Iyer by becoming a sponsor. Any amount is appreciated!