How to Host A Website on AWS EC2

Ravindra singh
3 min readJul 7, 2023

--

Setting Up Your EC2 Instance

When hosting your website, you need a virtual server on the cloud. AWS provides an EC2 instance as the virtual server.

To set up an EC2 instance, you will create a virtual machine (to host your website) in the cloud that you can access remotely. With an EC2 instance, you can install the server software and applications you need to host your website.

1. Sign in to your AWS Management Console.

2. Next, search for and select EC2 from the result list to navigate to the EC2 console.

3. Configure the following Name and OS Image for your EC2 instance:

4. Navigate to the EC2 console, and you will see your new instance in the. list, as shown below.

Congratulations! You have successfully set up an EC2 instance to host your website.

Installing a Web Server to Host a Website on AWS EC2

With your EC2 instance set up, you now need a way to deliver web content to users over the internet, a web server.

Many different web server options are available, including Apache, NGINX, and Microsoft IIS. But this tutorial uses Apache, one of the most popular and widely used web servers, open-source and highly configurable.

  1. You can use connect command to connect the Ec2 from UI

OR
2. You can also use the pem file to connect the ec2.

chmod 400 pemfile.pem
ssh -i pemfile.pem ec2-user@ipaddress

3. Now, run the following yum command to update the list of available packages. This command ensures you have the latest version of packages and security updates.

yum update -y

4. Once updated, run each command below to install the Apache web server (httpd)

yum install httpd -y

5. Now, run the below service commands to start the Apache web server (httpd) and check its status.

service httpd start
service httpd status

If all goes well, you will see the Apache test page, as shown below

Creating Your First Website

Navigate to the root directory of your web server (/var/www/html), which is main directory where all of the web content for your website is stored.

cd /var/www/html

Add the following code to your index.php file, save the changes, and close the file.

<!DOCTYPE html>
<html>

<head>
<title>Style Property</title>
</head>

<body style="background-image: -webkit-linear-gradient(left, white, black)">
<h1>Welcome to the Automation World!</h1>
</body>

</html>

Conclusion

Having a website is essential for almost every business. And the good news is that in this tutorial, you learned to host a website on AWS EC2.

--

--