DEV Community

Cover image for From Zero to Web Server: Deploying Apache on AWS EC2
Okoye Genevieve
Okoye Genevieve

Posted on

From Zero to Web Server: Deploying Apache on AWS EC2

STEP 1:This is where we set up our virtual server in the cloud.

Accessing EC2 Dashboard: First, navigate to the EC2 service within the AWS Console.
Instance Details: We give our instance a name (like web-server1), choose the operating system (e.g., Amazon Linux 2023 AMI), and select an instance type (like t2.micro for Free Tier eligibility, which defines its CPU and memory).
Key Pair: We create or select a key pair, which is a crucial security measure that allows us to securely connect to our instance later.
Network Settings & Security Groups: We configure network settings, ensuring a public IP is assigned. Crucially, we set up a security group (a virtual firewall). For a web server, we specifically enable SSH (Port 22) for secure remote access, and HTTP (Port 80) to allow web traffic to reach our server from the internet.
Finally, we click "Launch instance" to provision our server.

Image description
Image description
Image description
Image description

STEP 2:Once the instance is running, we need to connect to it to install software.

Locate your Key Pair: We navigate to the directory where our .pem key pair file is saved (e.g., your Downloads folder).
Set Permissions: Before using the key, we must set its permissions to be very restrictive (chmod 400 your-key.pem). This ensures only you can read it, which is required for SSH to work.
SSH Command: We then use the ssh command, specifying our key (-i), the default username (ec2-user for Amazon Linux), and the instance's Public IP address. This establishes a secure shell connection to our remote server.
Image description
Image description

STEP 3:Installing and Starting Apache HTTPD

With a secure connection established, we can now configure our web server.

Update Packages: First, we update the instance's package lists and existing software to the latest versions using sudo yum update -y.
Install Apache: Next, we install the Apache HTTP Server package with sudo yum install httpd -y.
Start Apache Service: We start the Apache service using sudo systemctl start httpd.
Enable on Boot: To ensure Apache restarts automatically if the server reboots, we use sudo systemctl enable httpd.
Check Status: We can verify the service is running correctly with sudo systemctl status httpd
Image description
Image description

STEP 4: Verifying Web Server Access

The final step is to confirm our web server is accessible from the internet.

Get Public IP: We go back to the EC2 Instances dashboard and copy the Public IPv4 address of our running instance.
Test in Browser: We paste this Public IP address into a web browser. If everything is configured correctly, you should see the default Apache test page, confirming your web server is live!
Security Group Adjustment (Optional but shown): The 2025-06-09_13h47_39.png image shows a step where you might have adjusted the SSH inbound rules to limit the source IP to a specific address, rather than "Anywhere". This is a good security practice to restrict who can connect via SSH.
Image description

Image description
Image description

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.