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.
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.
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.
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.
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.
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.
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.
5.1. After connecting to your instance, update the package manager and install necessary packages:
sudo yum update -y sudo yum install httpd -y
5.2. Start the Apache web server:
sudo service httpd start
5.3. Copy your website files to the
sudo cp -r /path/to/your/website/* /var/www/html/
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.
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".
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!
Follow me on Twitter: @CodezMikazuki
Thanks for reading, Malcz/Mika