RBCloud & DevOpsTHE PRACTICAL LEARNING LIBRARY
By Ravindra BagaleResources

CHAPTER 14 / 60

Apache on Amazon Linux and Ubuntu

Install Apache, serve a static page and trace a request through service, configuration and logs.

Concept + practical labBy Ravindra Bagale · ~5 min read · lab time additional

Before you begin

Use a dedicated EC2 lab. Allow TCP 80 from your intended visitors in its security group. Keep SSH restricted. If Nginx already owns port 80, stop it for this lab or configure different listener ports. Two processes cannot normally bind the same address and port.

Amazon Linux 2023

bash
sudo dnf install -y httpd
sudo systemctl enable --now httpd
printf '<h1>Apache on Amazon Linux</h1>\n' | sudo tee /var/www/html/index.html
sudo apachectl configtest
curl -I http://127.0.0.1/
sudo journalctl -u httpd -n 30 --no-pager

Main configuration is /etc/httpd/conf/httpd.conf; included site files normally go in /etc/httpd/conf.d/. Logs normally live in /var/log/httpd/.

Ubuntu 24.04 LTS

bash
sudo apt update
sudo apt install -y apache2
sudo systemctl enable --now apache2
printf '<h1>Apache on Ubuntu</h1>\n' | sudo tee /var/www/html/index.html
sudo apache2ctl configtest
curl -I http://127.0.0.1/
sudo journalctl -u apache2 -n 30 --no-pager

Configuration is under /etc/apache2/. Site definitions live in sites-available and are enabled with a2ensite; sites-enabled contains enabled links. Logs are normally in /var/log/apache2/.

How the request is served

The browser requests /. Apache selects a virtual host by address/port and hostname, maps the path under its DocumentRoot and evaluates directory/index rules and permissions. Static HTML is sent as bytes; Apache does not execute HTML. A missing file gives 404, forbidden directory/file access may give 403 and a broken service cannot return an HTTP response at all.

Verification

Open http://PUBLIC_IP/ from your laptop. Compare curl -I locally and remotely. Watch the access log while refreshing. If localhost works but the laptop times out, inspect AWS networking and host firewall rules. If you see an old welcome page, confirm the active DocumentRoot and overwrite only your disposable lab index.

Ownership and changes

Keep site files readable by the service account and parent directories traversable. Do not grant the web process write access to all application code. Back up a configuration before editing; syntax-test before reload. A configtest validates syntax, not whether every application request is correct.

Assignment

Create about.html, link to it from the index, inspect successful and missing-page log entries and explain the status codes. Stop/disable Apache before the Nginx-on-port-80 lab.

Official references

AL2023 LAMP tutorial Apache getting started

Ravindra’s Tip

Local curl चल रहा है लेकिन browser timeout देता है तो पहले network path देखो। HTML बदलने से blocked security group ठीक नहीं होगा।

Interview and revision check

Does configtest prove the website works?

No. It checks configuration syntax. You must still test active virtual-host selection, file access, network reachability and application responses.

Ravindra Bagale · Cloud & DevOps Academy · Handbook and project downloads