Host your personal site on AWS EC2 Instance

Are you looking to host your own personal website but unsure where to start? Amazon Web Services (AWS) offers a convenient and flexible solution through its Elastic Compute Cloud (EC2) service. In this guide, we'll walk you through the process of configuring and setting up an EC2 instance under the free tier, installing and configuring Apache HTTP Server (httpd), and configuring inbound rules to allow HTTP and HTTPS traffic. Let's get started!

Step 1: Configuring and Setting Up an EC2 Instance

  1. Sign in to AWS Console: Log in to your AWS Management Console at https://aws.amazon.com/console/.

  2. Navigate to EC2 Dashboard: From the AWS services menu, select EC2 under the Compute section.

  3. Launch Instance: Click on the "Launch Instance" button to start the instance creation process.

  4. Choose an Amazon Machine Image (AMI): Select an AMI. For this guide, we recommend choosing a Linux-based AMI such as Amazon Linux 2 or Ubuntu Server.

  5. Choose Instance Type: Select an instance type. Since we're under the free tier, choose a t2.micro instance type.

  6. Configure Instance: Leave the default settings or customize as needed. Make sure to enable "Auto-assign Public IP" to ensure your instance has a public IP address.

  7. Add Storage: Configure storage settings. The default settings should be sufficient for most use cases.

  8. Add Tags (Optional): Add tags to your instance for better organization and management.

  9. Configure Security Group: Create a new security group or select an existing one. Ensure that inbound rules allow HTTP (port 80) and HTTPS (port 443) traffic from anywhere (0.0.0.0/0) for now. You can tighten these rules later based on your requirements.

  10. Review and Launch: Review your instance configuration and click "Launch." You'll be prompted to create a new key pair or select an existing one. Create a new key pair and download the private key file (*.pem) to a secure location.

  11. Launch Instance: Click "Launch Instances" to create your EC2 instance.

Step 2: Installing and Configuring Apache HTTP Server (httpd)

  1. Connect to your EC2 Instance: Open a command prompt or terminal and navigate to the directory where your private key file (*.pem) is located.

  2. Change Permissions of the Key Pair: To ensure the security of your private key, run the following command:

     chmod 400 your_key_pair.pem
    
  3. Connect to the Instance: Use SSH to connect to your EC2 instance:

     ssh -i your_key_pair.pem ec2-user@your_instance_public_ip
    
  4. Switch to Root User: Once connected, switch to the root user for administrative privileges:

     sudo su -
    
  5. Install Apache HTTP Server: Use yum package manager to install Apache HTTP Server:

     yum install httpd
    
  6. Start Apache HTTP Server: Once installed, start the Apache service:

     systemctl start httpd
    
  7. Verify Status: Check the status of the Apache service to ensure it's running:

     systemctl status httpd
    

Step 3: Configuring Inbound Rules for HTTP and HTTPS

  1. Navigate to EC2 Dashboard: Go back to the EC2 Dashboard in the AWS Management Console.

  2. Select Security Groups: Select the security group associated with your EC2 instance.

  3. Edit Inbound Rules: Click on the "Inbound Rules" tab and edit the rules to allow HTTP (port 80) and HTTPS (port 443) traffic from anywhere (0.0.0.0/0).

  4. Save Changes: Save the changes to update the security group.

Ready to Deploy!

Congratulations! You've successfully configured and set up an EC2 instance on AWS, installed and configured Apache HTTP Server, and configured inbound rules to allow HTTP and HTTPS traffic. You're now ready to deploy your personal website or web application on your EC2 instance. Stay tuned for the next steps on deploying your content and securing your EC2 instance.