Launching an EC2 and installing Apache with a custom webpage

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!

No alt text provided for this image

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

No alt text provided for this image

  • Create a free account in?AWS?and log in to the AWS console
  • Create a VPC

Search for VPC and click on it

No alt text provided for this image

Click the “Create VPC” button to create a VPC

No alt text provided for this image
No alt text provided for this image

The VPC is created

No alt text provided for this image

  • Create a subnet in the VPC

Click “Subnet” then click “Create Subnet”

No alt text provided for this image

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”.

No alt text provided for this image

After the subnet is created, edit the settings to make it public.

No alt text provided for this image

Check the box of “Enable auto-assign public IPv4 address” and save the change.

No alt text provided for this image

  • Create an internet gateway

Click “Internet gateways” then click “Create internet gateways”

No alt text provided for this image

Fill out the Name tag file and click “Create internet gateways”.

No alt text provided for this image

Attach the internet gateway to the VPC created

No alt text provided for this image

Pick the VPC we want to use and click “Attach internet gateway”

No alt text provided for this image

  • Set up the route table

Click “Route table” then click “Create route table”

No alt text provided for this image

Select the VPC we want to use and click “Create route table”.

No alt text provided for this image

Now the route table is created. Check the route table we created and click the “Routes” tab then click “Edit routes”.

No alt text provided for this image

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.

No alt text provided for this image

Click the “Subnet associations” tab and click “Edit subnet associations”

No alt text provided for this image

Check the subnet we just created and save it.

No alt text provided for this image

  • Launch an EC2 instance

Search for the EC2 service like what we just search for VPC. Then click “Launch Instance”.

No alt text provided for this image

Fill it out with Amazon Linux, t2.micro (which is free) and generate the key pair.

No alt text provided for this image
No alt text provided for this image

Select the VPC and Subnet we just created.

No alt text provided for this image

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.

No alt text provided for this image

Now we can launch the instance.

No alt text provided for this image

Clicking “View all instances”, we can see our instance is listed. Wait until it is running.

No alt text provided for this image

  • Connect the EC2 instance using a SSH client.

Click “connect” and go to the “SSH client” tab. Follow the instruction to connect to the instance.

No alt text provided for this image

Follow the instruction to connect to the instance.

No alt text provided for this image

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

No alt text provided for this image
No alt text provided for this image

Find the IPv4 address of the EC2 instance

No alt text provided for this image

The Apache Server is running and the welcom page is customized to our custom webpage.

No alt text provided for this image

Step 3 Push the script to Github

Clone the repository from Github

No alt text provided for this image

Copy the script to the local branch

No alt text provided for this image

Do git add, git commit and push it to remote

No alt text provided for this image
No alt text provided for this image

Do git add, git commit and push it to remote

No alt text provided for this image
No alt text provided for this image

Now the project is done. Thank you for reading! Let’s meet next time.

要查看或添加评论,请登录

Weiping Zhang的更多文章

社区洞察

其他会员也浏览了