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
Sign in to AWS Console: Log in to your AWS Management Console at https://aws.amazon.com/console/.
Navigate to EC2 Dashboard: From the AWS services menu, select EC2 under the Compute section.
Launch Instance: Click on the "Launch Instance" button to start the instance creation process.
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.
Choose Instance Type: Select an instance type. Since we're under the free tier, choose a t2.micro instance type.
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.
Add Storage: Configure storage settings. The default settings should be sufficient for most use cases.
Add Tags (Optional): Add tags to your instance for better organization and management.
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.
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.
Launch Instance: Click "Launch Instances" to create your EC2 instance.
Step 2: Installing and Configuring Apache HTTP Server (httpd)
Connect to your EC2 Instance: Open a command prompt or terminal and navigate to the directory where your private key file (*.pem) is located.
Change Permissions of the Key Pair: To ensure the security of your private key, run the following command:
chmod 400 your_key_pair.pem
Connect to the Instance: Use SSH to connect to your EC2 instance:
ssh -i your_key_pair.pem ec2-user@your_instance_public_ip
Switch to Root User: Once connected, switch to the root user for administrative privileges:
sudo su -
Install Apache HTTP Server: Use yum package manager to install Apache HTTP Server:
yum install httpd
Start Apache HTTP Server: Once installed, start the Apache service:
systemctl start httpd
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
Navigate to EC2 Dashboard: Go back to the EC2 Dashboard in the AWS Management Console.
Select Security Groups: Select the security group associated with your EC2 instance.
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).
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.