AWS EC2 Webserver Tutorial

AWS EC2 Webserver Tutorial

Launch an EC2 instance in the AWS console. For this tutorial we will be using the Amazon Linux AMI. Configure your security group,

port 80` open to `0.0.0.0/0

Create and download the keypair pem file and we’re ready to log into our instance.

Before we can log in, we need to change the permissions on the PEM file.

chmod 400 /path/to/pem

To SSH into our EC2 instance, run this command with the correct values:

ssh -i "keyname.pem" ec2-user@ipaddress

Once we’re logged in, let’s make sure our instance is up to date.

sudo yum update -y

To instance our Apache webserver we need to run:

sudo yum install httpd -y

Let’s start httpd by running:

sudo service httpd start

To confirm the service is running:

service httpd status

You should see an output similar to:

httpd (pid xxxx) is running...

Now that our webserver is up and running, if you go to the instances public IP Address, you should see the Amazon Linux AMI Test Page.

We can now customize the index.html page with our custom html.

First we need to change directory.

cd /var/www/html

This directory will be empty, we need to create an index.html with our custom code.

We can create a simple webpage to ensure everything is working as expected.

vim index.html

A simple test webpage:

<html>
<body>

My EC2 Webserver.

</body>
</html>

If we go to the instances IP again, our changes should be automatically propagated.

If you’re still seeing the default Apache splashpage, restart httpd:

service httpd restart