Home » Java » Enterprise Java » How to install Apache Web Server on EC2 Instance using User data script

About Gaurav Bhardwaj

Gaurav Bhardwaj
Gaurav has done Masters in Computer Applications(MCA) and is working in Software development field for more than 10 years in Java/J2EE technologies. He is currently working with one of top MNC. He has worked on various frameworks like Struts, Spring, Spring Boot, Angular JS, JSF, Velocity, iBatis, MyBatis, Hibernate, JUnit, Mockito, Dozzer. He likes to explore new technologies and share his thoughts by writing a technical blog. He is the founder of JavaSolutionsGuide.blogspot.com.

How to install Apache Web Server on EC2 Instance using User data script

Hello Friends,

In this tutorial, we will see how we can install Apache Web Server on EC2 instance using user data script.

In one of my previous tutorials,I have already explained how we can launch an EC2 instance using AWS console.If you have not already gone through that,I will recommend  to please go through that

first ,as that is prerequisite for this tutorial.Here is the link to that tutorial 
How to Launch an EC2 Instance in AWS.

– When you are in Step 6 of the above tutorial and you scroll down the “Configure Instance               Details”,you will see following “Advanced Details” section :

– In the User Data section ,paste the following shell script to install Apache Web Server


#!/bin/bash
yum update -y
yum install -y httpd.x86_64
systemctl start httpd.service
systemctl enable httpd.service
echo “Hello World from $(hostname -f)” > /var/www/html/index.html

– Click on “Add Storage”  and proceed with Steps mentioned in 
How to Launch an EC2 Instance in AWS

– One more thing that you need to do is to edit the Security Group and add rule to allow Http traffic on port 80.

For that,as can be seen in Step 13, you need to look into the Description tab and below “iPV4 public IP” ,you will find “Security groups”.Click on security group link and it will take you to “Security Groups” page, where you can click on “Security Group ID” and then click on “Edit inbound rules” and add rule to allow http traffic on port 80 from anywhere on internet.

– Now copy the public IP of your EC2 instance from “Description” .

Note : As the referred tutorial(How to Launch an EC2 Instance in AWS) was created some time back, so below screenshot has different instance Id and IP than the one mentioned in previous tutorial.

-Hit the IP  in the browser.You will be able to see “Hello World from ip-172-31-31-194.eu-west-2.compute.internal” in your browser,which is served by Apache server on EC2 instance.

Summary

In this tutorial, we learnt that 

– How we can install Apache Web Server on EC2 instance.

– Make sure that security group has inbound and outbound rule to allow Http traffic on port 80.

Thanks for reading.Please subscribe the blog, if you liked the post to get new post directly in your inbox.

Published on Java Code Geeks with permission by Gaurav Bhardwaj, partner at our JCG program. See the original article here: How to install Apache Web Server on EC2 Instance using User data script

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments