Day 9: Step-by-Step Guide: Creating an EC2 Instance to Host a 'Hello, World' Website🌐
Introduction
In this blog post, we will walk through the steps to create an Amazon EC2 instance and set up a basic website. By the end of this tutorial, you will have a running website on an EC2 instance.🌐💻
Prerequisites⚠
Before you start, ensure you have:
An AWS account
Basic understanding of AWS services
A domain name (optional)
Step 1: Launch an EC2 Instance🚀
Log in to AWS Management Console
- Navigate to the AWS Management Console.
Open EC2 Dashboard
- In the services menu, select "EC2" to open the EC2 dashboard.
Launch Instance
- Click the "Launch Instance" button.
Choose an Amazon Machine Image (AMI)
- Select an AMI. For this guide, we will use the "Amazon Linux 2 AMI" (Free tier eligible).
Choose an Instance Type
- Select an instance type. The "t2.micro" instance is sufficient for a basic website (Free tier eligible).
Configure Instance Details
Configure the instance settings. You can leave most settings as default.
Ensure you select the correct VPC and subnet if you have specific networking requirements.
Optionally, add an IAM role if your instance needs access to other AWS services.
Add Storage
- The default storage settings should be sufficient. Ensure the root volume has enough space for your website files.
Add Tags
- Add tags to your instance for better organization. For example,
Key: Name, Value: MyWebsiteInstance
.
- Add tags to your instance for better organization. For example,
Configure Security Group
Create a new security group or select an existing one.
Add a rule to allow HTTP traffic (port 80) from anywhere.
Add a rule to allow SSH traffic (port 22) from your IP address for secure access.
Review and Launch
Review your settings and click "Launch."
Select an existing key pair or create a new one to access your instance securely via SSH.
Launch Instance
- Click "Launch Instances" and then "View Instances" to see your newly created instance.
Step 2: Connect to Your EC2 Instance🔗
Access Your Instance
Select your instance from the EC2 dashboard.
Click "Connect" and follow the instructions to connect via SSH using your key pair.
SSH Connection Command
Use the following command format to connect to your instance:
shCopy codessh -i "your-key-pair.pem" ec2-user@your-instance-public-dns
Step 3: Set Up a Web Server🌐
Update Your Instance
Run the following commands to update your instance:
shCopy codesudo yum update -y
Install Apache Web Server
Install Apache using the following command:
shCopy codesudo yum install httpd -y
Start Apache
Start the Apache service and enable it to start on boot:
shCopy codesudo systemctl start httpd sudo systemctl enable httpd
Test Apache Installation
- Open a web browser and enter your instance’s public IP address. You should see the Apache test page.
Step 4: Deploy Your Website💻
Create a Simple HTML Page
Create an HTML file in the Apache document root directory:
shCopy codesudo echo "<html><body><h1>Hello, World!</h1></body></html>" > /var/www/html/index.html
Verify the Website
- Open your web browser and navigate to your instance’s public IP address. You should see "Hello, World!" displayed.
Step 5: (Optional) Associate a Domain Name🆎
Configure a Domain Name
- If you have a domain name, configure your DNS settings to point to your EC2 instance’s public IP address.
Update Security Group
- Ensure your security group allows traffic on port 80 (HTTP) and port 443 (HTTPS) if you plan to use SSL.
Conclusion💡
In this guide, we walked through the steps to launch an EC2 instance, set up a basic web server, and deploy a simple 'Hello, World' website. This setup provides a foundation for more complex web applications.
I hope this detailed guide helps you understand the process of setting up EC2 for webserver. Practice these steps on your own AWS console and practice. Stay tuned for more AWS insights!!⚜ If you found this blog helpful, share it with your network! 🌐😊
Happy cloud computing! ☁️🚀
Subscribe to my newsletter
Read articles from Shailesh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Shailesh
Shailesh
As a Solution Architect, I am responsible for designing and implementing scalable, secure, and efficient IT solutions. My key responsibilities include: 🔸Analysing business requirements and translating them into technical solutions. 🔸Developing comprehensive architectural plans to meet organizational goals. 🔸Ensuring seamless integration of new technologies with existing systems. 🔸Overseeing the implementation of projects to ensure alignment with design. 🔸Providing technical leadership and guidance to development teams. 🔸Conducting performance assessments and optimizing solutions for efficiency. 🔸Maintaining a keen focus on security, compliance, and best practices. Actively exploring new technologies and continuously refining strategies to drive innovation and excellence.