Deploying a Simple Website on an EC2 Instance with Ubuntu/RedHat/CentOs: A Beginner's Guide

Deploying a Simple Website on an EC2 Instance with Ubuntu/RedHat/CentOs: A Beginner's Guide

Amazon EC2 (Elastic Compute Cloud) is a cloud-based service that allows you to run applications and services in the cloud. In this blog, we will discuss how to deploy a simple website on an EC2 instance running Ubuntu.

Step 1: Launch an EC2 instance Login to your AWS account and navigate to the EC2 dashboard. Click on the "Launch Instance" button and select an Ubuntu server instance. Choose the appropriate instance type and configuration for your needs, then follow the prompts to launch the instance.

Step 2: Connect to the instance After launching the instance, connect to it using SSH. You can do this through the EC2 dashboard or by using a terminal client such as PuTTY.

chmod 400 my-key-pair.pem
ssh -i my-key-pair.pem ubuntu@public-ip-address

Once you're connected, you should see the Ubuntu command prompt.

Step 3:

Ubuntu

Install Apache To host your website, you need to install a web server. Apache is a popular choice for hosting websites on Ubuntu. To install Apache, run the following command:

sudo apt-get update
sudo apt-get install apache2

RedHat/CentOs

sudo yum update
sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd

Step 4: Configure Apache By default, Apache serves files from the /var/www/html directory. You can create a simple HTML file to test the server. To do this, create a new file called index.html in the /var/www/html directory:

sudo nano /var/www/html/index.html

Add the following HTML code to the file:

<html>
<head>
    <title>My Website</title>
</head>
<body>
    <h1>Welcome to my website</h1>
    <p>This is a simple website hosted on an EC2 instance</p>
</body>
</html>

or copy all your files to /var/www/html/ this directory. And make sure your main file's name should be index.html.

Step 5(optional): Configure your domain name To access your website using your registered domain name, you need to configure your domain name provider to point to your EC2 instance's public IP address. This typically involves adding an A record to your DNS configuration.

Now you can access your website by domain name(if you configured it), or access it by public IP address which can be available on the AWS ec2 instance page.

Conclusion In this blog, we discussed how to deploy a simple website on an EC2 instance running Ubuntu. This is just the beginning of what you can do with EC2, but it provides a good starting point for hosting basic websites and applications in the cloud. Thank you :)

Did you find this article valuable?

Support Dhananjay Patel by becoming a sponsor. Any amount is appreciated!