Listen to this Post
Deploying a static website on an EC2 instance using Apache on a custom port is a great way to understand AWS services and web hosting. Below is a breakdown of the process along with verified commands and code snippets:
1. Setting up an EC2 Instance
Launch an EC2 instance using the AWS Management Console or AWS CLI:
aws ec2 run-instances --image-id ami-0abcdef1234567890 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-903004f8
2. Installing Apache and Configuring Custom Port
SSH into your EC2 instance and install Apache:
sudo apt update sudo apt install apache2
Edit the Apache configuration file to change the default port to 33:
sudo nano /etc/apache2/ports.conf
Change `Listen 80` to `Listen 33`.
- Creating a Static Website and Managing File Permissions
Create a static website in the `/var/www/html` directory:
sudo nano /var/www/html/index.html
Set proper permissions:
sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html
4. Configuring Apache Virtual Hosts
Edit the default virtual host file:
sudo nano /etc/apache2/sites-available/000-default.conf
Change `` to ``.
5. Setting Up Security Groups
Allow inbound traffic on port 33 in the EC2 security group:
aws ec2 authorize-security-group-ingress --group-id sg-903004f8 --protocol tcp --port 33 --cidr 0.0.0.0/0
6. Assigning an Elastic IP
Allocate and associate an Elastic IP to your instance:
aws ec2 allocate-address aws ec2 associate-address --instance-id i-0abcd1234efgh5678 --public-ip 203.0.113.0
Check out the full project on GitHub: https://lnkd.in/et6iaFxJ.
What Undercode Say
Deploying a static website on an EC2 instance with Apache on a custom port is a practical way to learn AWS, cloud infrastructure, and web server management. This project highlights the importance of understanding security groups, virtual hosts, and Elastic IPs in cloud environments. For further exploration, consider diving into advanced topics like load balancing with AWS Elastic Load Balancer (ELB) or automating deployments using AWS CodeDeploy.
Here are some additional commands to enhance your Linux and AWS skills:
– Check Apache Status:
sudo systemctl status apache2
– Restart Apache:
sudo systemctl restart apache2
– List EC2 Instances:
aws ec2 describe-instances
– Terminate an EC2 Instance:
aws ec2 terminate-instances --instance-ids i-0abcd1234efgh5678
– Check Disk Space:
df -h
– Monitor Network Traffic:
sudo apt install nethogs sudo nethogs
For more resources, visit the official AWS documentation: https://aws.amazon.com/documentation/.
References:
Hackers Feeds, Undercode AI


