CodeNewbie Community 🌱

Cover image for Step-by-step guide: Creating an EC2 Instance to Host your website on AWS
Malcolm Mikazuki
Malcolm Mikazuki

Posted on

Step-by-step guide: Creating an EC2 Instance to Host your website on AWS

I have been using AWS tools for awhile now for a few different projects having worked on for clients so I thought it would be beneficial to post here about how you can best utitlize to host your websites.

Introduction:

In this tutorial, we will walk you through the process of setting up an Amazon EC2 (Elastic Compute Cloud) instance to host your website on AWS (Amazon Web Services). EC2 provides scalable computing resources and allows you to deploy and manage virtual servers in the cloud. By the end of this guide, you'll have a functional EC2 instance running your website, accessible to users from anywhere in the world.

Prerequisites:

Before you begin, make sure you have the following:

  • An AWS account: If you don't have one, sign up for a free AWS account at https://aws.amazon.com/.
  • A registered domain name: Ensure you have a registered domain name from a domain registrar like GoDaddy or Route 53.

Step 1: Launching an EC2 Instance

1.1. Sign in to your AWS Management Console and navigate to the EC2 Dashboard.
1.2. Click the "Launch Instance" button to start the instance creation process.
1.3. Choose an Amazon Machine Image (AMI) that best suits your website's requirements. For a web server, we recommend using Amazon Linux 2 or any other Linux distribution.
1.4. Select an Instance Type based on the resources you need. For small websites, a t2.micro instance is a good starting point.
1.5. Configure Instance Details such as the number of instances, network settings, and storage.

Step 2: Setting up Security Groups

2.1. In the "Configure Security Group" step, create a new security group or choose an existing one.
2.2. Allow inbound traffic on port 80 (HTTP) and port 443 (HTTPS) to make your website accessible over the internet.
2.3. You may also allow SSH access (port 22) if you plan to manage the instance via SSH.

Step 3: Review and Launch

3.1. Review your instance configuration and click "Launch."
3.2. Choose an existing key pair or create a new one to securely access your EC2 instance via SSH.

Step 4: Connecting to Your EC2 Instance

4.1. Once your instance is running, select it from the EC2 Dashboard and click "Connect."
4.2. Follow the provided instructions to connect to your instance using SSH.

Step 5: Configuring the Web Server

5.1. After connecting to your instance, update the package manager and install necessary packages:

sudo yum update -y
sudo yum install httpd -y
Enter fullscreen mode Exit fullscreen mode

5.2. Start the Apache web server:

sudo service httpd start
Enter fullscreen mode Exit fullscreen mode

5.3. Copy your website files to the /var/www/html/ directory:

sudo cp -r /path/to/your/website/* /var/www/html/
Enter fullscreen mode Exit fullscreen mode

Step 6: Assigning Elastic IP (Optional)

6.1. For a stable IP address, go to the EC2 Dashboard, select "Elastic IPs" from the sidebar, and allocate a new Elastic IP address.
6.2. Associate the Elastic IP with your running instance to ensure the IP address remains the same, even if the instance is stopped and started.

Step 7: Configuring DNS Settings

7.1. Go to your domain registrar's website and configure the DNS settings to point to your EC2 instance's public IP or Elastic IP.
7.2. Create an "A" record for your domain, and optionally a "CNAME" record for "www.yourdomain.com".

Conclusion:

Congratulations! You have successfully created an EC2 instance on AWS and configured it to host your website. By following this guide, you've learned how to set up a web server, connect to your instance, and configure DNS settings to make your website accessible to users worldwide. AWS EC2 offers a scalable and reliable solution for hosting your website, ensuring high availability and performance. Happy hosting!

Image description

Follow me on Twitter: @CodezMikazuki

Thanks for reading, Malcz/Mika

Top comments (1)

Collapse
 
mikazukiaugus profile image
Malcolm Mikazuki

Hey Matt,
Yes I taking the defaults while going through the process is ok for most.

I think Godaddy may be a bit more easier to navigate than Route 53 sometimes AWS steps can feel a bit more complicated.

In all honesty what I find to deal with easiests most is Google domains, the process is more streamlined and easier to follow.