AWS EC2 , Apache and the BASH script that starts it all.
This week’s project was another dive into the many ways that cloud computing utilizes different technology types and makes them cohesive in function. I created an EC2 instance in AWS and spun up an Apache web server using a script. Let’s see how
Prerequisites for this project:
- AWS free tier account (or higher)
First I had to spin up an EC2 instance. You can find information directly from AWS on how to do this with their official documentation page for EC2 instances here.
Once the selections have been made for the AMI (Amazon Linux), instance type (t2.micro), security group, key pair and other options for the EC2 instance I had to open the advanced settings tab in the menu and access the ‘user data’ field. Once there, I had a prepared bash script to configure an apache server on my EC2 instance that needed to be pasted there. You can see the script in the image below:
To break down each block of the script:
sudo yum check-update
sudo yum update
The above commands check for all update packages available and run the updates on the system.
sudo yum -y install httpd
sudo systemctl enable httpd.service
sudo systemctl start httpd.service
sudo systemctl status httpd
The above commands tell the system to install, enable and start Apache web services. The last piece of the command block allows you to verify that the new service is running successfully.
sudo yum -y install firewalld
sudo systemctl start firewalld
systemctl status firewalld
The above commands start a virtual firewall on the system and allow you to control the flow of different traffic types in and out of it. The final piece of this command block verifies the firewall is up and running.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
The above commands initiate the permission of web traffic on the system to let the Apache web server communicate with the internet.
After the EC2 instance was built, I connected to it via SSH (how to connect to EC2 via SSH) and had to verify that my Apache server was correctly created and functioning.
To do this I had to;
1.) Acquire the IP address of the server using the command below:
curl -4 icanhazip.com
If done correctly, the resulting text will be a public IPv4 address for the Apache server.
2.) Copy the IP address and paste it into aweb browser to see if it is accessible from the internet
The resulting web page displays an Apache test page. Mission Complete!