Launching an EC2 and installing Apache with a custom webpage
Hello friends! Welcome to my first Cloud project. In this post, I am going to talk about how to launch an EC2 instance in a subnet, together with a VPC and an internet gateway, so it can connect to the internet. And then we will install an Apache Web Server on the EC2 instance with a custom webpage. Below is the diagram about how the Apache server works on an EC2 instance. OK, let’s start!
Step 1 Launch an EC2 Amazon Linux t2.micro (free tier) in a public subnet
We need to create/launch the below services in AWS
Search for VPC and click on it
Click the “Create VPC” button to create a VPC
The VPC is created
Click “Subnet” then click “Create Subnet”
Select the VPC we just created and provide the IPv4 CIDR block which should be in the range of VPC CIDR we just set. And click “Create Subnet”.
After the subnet is created, edit the settings to make it public.
Check the box of “Enable auto-assign public IPv4 address” and save the change.
Click “Internet gateways” then click “Create internet gateways”
Fill out the Name tag file and click “Create internet gateways”.
Attach the internet gateway to the VPC created
Pick the VPC we want to use and click “Attach internet gateway”
Click “Route table” then click “Create route table”
Select the VPC we want to use and click “Create route table”.
Now the route table is created. Check the route table we created and click the “Routes” tab then click “Edit routes”.
Click “Add route” and fill out with Destination set to 0.0.0.0/0 which is the internet and Target set to the internet gateway we just created. Then save the changes.
Click the “Subnet associations” tab and click “Edit subnet associations”
Check the subnet we just created and save it.
领英推荐
Search for the EC2 service like what we just search for VPC. Then click “Launch Instance”.
Fill it out with Amazon Linux, t2.micro (which is free) and generate the key pair.
Select the VPC and Subnet we just created.
Also we create a security group that allows inbound traffic on HTTP for 0.0.0.0/0 and allows inbound traffic on SSH from our local ip address.
Now we can launch the instance.
Clicking “View all instances”, we can see our instance is listed. Wait until it is running.
Click “connect” and go to the “SSH client” tab. Follow the instruction to connect to the instance.
Follow the instruction to connect to the instance.
Great! The EC2 instance is ready for use!
Step 2 install Apache with a custom webpage
Use the following Bash script to install an Apache Web Server and revise the index.html to a custom webpage.
First we?upgrade?all of the packages on the system. Then we?install?the Apache Web Server. After that, we?start?and?enable?the server. At last, we change the index.html to a customized one so the welcome webpage display our own information.
sudo yum update -
sudo yum install -y httpd.x86_64
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
echo “Greetings from Pingping! Hello my friends~” | sudo tee /usr/share/httpd/noindex/index.htmly
Run the script
Find the IPv4 address of the EC2 instance
The Apache Server is running and the welcom page is customized to our custom webpage.
Step 3 Push the script to Github
Clone the repository from Github
Copy the script to the local branch
Do git add, git commit and push it to remote
Do git add, git commit and push it to remote
Now the project is done. Thank you for reading! Let’s meet next time.