AWS Lab: Setting up an EC2 instance as a WebServer

AWS is platform provided by Amazon which deals with Cloud Computing. Learning about Cloud Computing and AWS was one of the first steps I took towards understanding Cloud Concepts.

In this article, I would like to share  my experience of getting introduced to one of AWS services , Amazon EC2 instance and how it’s used  to create a web server.

So what is an Amazon EC2 instance?

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction. It provides you with complete control of your computing resources and lets you run on Amazon’s proven computing environment.

Creating and launching an EC2 Instance

To create and launch an instance we have to login to AWS Management Console , Then under services we’ll find EC2 instance and proceed to go there to create an instance.

Things to keep in mind while creating an instance:-

1.Choosing an AMI ( Amazon Machine Images)

An Amazon Machine Image (AMI) is a template that contains a software configuration (for example, an operating system, an application server, and applications). I chose the Amazon Linux2( 64-bit).

2.Choosing the type of instance

There are different types of instance to chose from according to the work. General purpose, Storage optimized, Compute optimized, Memory Optimized and Accelerated optimized are the types of instances provided by AWS.

3. Adding Storage

The Amazon ec2 by default comes with a storage attached to it. The user can choose a different storage services to add  so that data is safe even when the instance is terminated.

4. Configuring Security Groups

A firewall needs to specified in the instance as a security measure. User can specify and allow inbound or outbound of access to the instances.

After reviewing  these steps the ec2 is ready to be created and launched.

Configure EC2 Instance to be a Web Server

After launching an instance , we need to connect to the instance and run a series of commands to have the web server up and running.

To connect to an instance we have to Login to the Amazon EC2 console then in the navigation pane, choose Instances and  Select the instance which was created and click on Connect. then  proceed to connect by Choosing EC2 Instance Connect. After doing this , it’ll open a new CLI (Command Line Interface) where the commands will be written and executed.

After having the web server installed, permissions need to be set as to who can makes changes or update the web server. The following series of commands will help to install the web server in the instance:

sudo yum update -y
sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
sudo yum install -y httpd mariadb-server
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl is-enabled httpd

sudo usermod -a -G apache ec2-user
groups ec2-user
sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;

After having the web server installed, permissions need to be set as to who can makes changes or update the web server.

The server should be properly working at this point and can be checked by accessing the IP address , which you can get from your instance dashboard.

What is next?

As your web server is up and running it is up to you to add content and modify it according to your liking.

Personal Thoughts and Experience

Just by looking at the steps to creating a web server might look intimidating , time consuming and you might get errors along the way but as practice makes you better, the process would be effortlessly simple in no time. If I as a person who has been newly introduced to Cloud Computing and AWS could say and do this then so could anyone else too.

Scroll to top

Subscribe

* indicates required