How to Install Apache (httpd) on Amazon Linux 2023 (EC2)
To install Apache on an Amazon Linux 2023 EC2 instance, run sudo yum install -y httpd, then start it with sudo service httpd start and enable it at boot with sudo systemctl enable httpd. Allow HTTP (TCP port 80) in the instance's security group and open http://<PUBLIC_IP> in a browser. On Amazon Linux the Apache package and service are called httpd, and the default web root is /var/www/html.
Hello friends! We saw Nginx earlier, now it's Apache. On the first day of my class one question always comes up: "Sir, the apache2 command doesn't work!" Because on Amazon Linux, Apache is called httpd. In this guide we install Apache and put your first page live. Let's type along together.
नमस्कार मित्रांनो! Nginx आपण आधी पाहिला, आता Apache. माझ्या क्लास मध्ये पहिल्या दिवशी एक प्रश्न नक्की येतो: "सर, apache2 कमांड चालत नाही!" कारण Amazon Linux वर Apache चं नाव आहे httpd. या गाइड मध्ये Apache इन्स्टॉल करून तुमचं पहिलं पेज लाइव्ह करूया. चला, माझ्या सोबत टाइप करा.
नमस्कार दोस्तों! Nginx हमने पहले देखा, अब Apache. मेरी क्लास में पहले दिन एक सवाल ज़रूर आता है: "सर, apache2 कमांड नहीं चल रही!" क्योंकि Amazon Linux पर Apache का नाम है httpd. इस गाइड में Apache इंस्टॉल करके आपका पहला पेज लाइव करेंगे. चलो, मेरे साथ टाइप करो.
Quick answer
On an Amazon Linux 2023 EC2 instance, run these commands, allow HTTP (TCP port 80) in the security group, and open http://<PUBLIC_IP>:
sudo yum install -y httpd
sudo service httpd start
sudo systemctl enable httpd
sudo apachectl configtest # expect "Syntax OK"
curl -I http://localhost # expect HTTP/1.1 200 OK (or 403 before you add a page)
What do I need before installing Apache?
- An EC2 instance running Amazon Linux 2023 with a public IP. New to this? Follow How to Launch an EC2 Instance in AWS.
- An SSH session on that instance. See How to SSH into EC2 from Windows, Mac and Linux.
- A security group that allows HTTP 80 from Anywhere-IPv4. See How to Open Port 80 and 443 in an EC2 Security Group.
- Nothing else on port 80. If you followed the Nginx guide on the same server, stop Nginx first (Step 1).
How does a request reach Apache on EC2?
The browser sends a Request over the internet. The security group lets it in on port 80, Apache (httpd) on EC2 answers with a page from /var/www/html, and the Response travels back.
ब्राउझर इंटरनेट वरून Request पाठवतो. Security group तिला पोर्ट 80 वर आत सोडतो, EC2 वरचा Apache (httpd) /var/www/html मधलं पेज देतो, आणि Response परत जातो.
ब्राउज़र इंटरनेट से Request भेजता है. Security group उसे पोर्ट 80 पर अंदर आने देता है, EC2 वाला Apache (httpd) /var/www/html से पेज देता है, और Response वापस जाता है.
How do I install Apache on Amazon Linux 2023?
Step 1 — Free port 80 (only if Nginx is installed)
Only one program can listen on port 80. If Nginx runs on this instance, stop and disable it first:
sudo service nginx stop 2>/dev/null
sudo systemctl disable nginx 2>/dev/null
sudo ss -tlnp | grep :80 # no output = port 80 is free
Step 2 — Install the httpd package
sudo yum install -y httpd
On Amazon Linux 2023, CentOS Stream 9 and RHEL, Apache is the httpd package and the httpd service. On Ubuntu it is apache2.
Step 3 — Start Apache and enable it at boot
Apache does not start by itself after install on Amazon Linux 2023:
sudo service httpd start
sudo systemctl enable httpd
sudo service httpd status # look for "active (running)"
Step 4 — Test the configuration and the service
sudo apachectl configtest # expect "Syntax OK"
curl -I http://localhost # a response line proves Apache answers
Before you add a page, Apache may answer with its test page (a 403 status is normal at this point, because /var/www/html is still empty).
Step 5 — Add your own page
The default web root is /var/www/html. Write a simple test page:
echo "<h1>Hello from Apache on EC2</h1>" | sudo tee /var/www/html/index.html
curl http://localhost
Now open http://<PUBLIC_IP> in your browser — http, not https. Your page is live! 🎉
Ravindra Bagale's Tip
Many students type sudo service apache2 start on Amazon Linux and get Unit not found. There, Apache is called httpd – the package, the service and the log folder /var/log/httpd/ are all httpd. Only on Ubuntu is it apache2. Check which OS you are on first with cat /etc/os-release.
Ravindra Bagale's Tip – मराठी
खूप स्टुडंट्स Amazon Linux वर sudo service apache2 start टाइप करतात आणि Unit not found येतं. तिथे Apache चं नाव httpd आहे – package, service आणि log फोल्डर /var/log/httpd/ सगळे httpd. Ubuntu वर मात्र apache2. कोणत्या OS वर आहात ते आधी cat /etc/os-release ने बघा.
Ravindra Bagale's Tip – हिंदी
बहुत स्टूडेंट्स Amazon Linux पर sudo service apache2 start टाइप करते हैं और Unit not found आता है. वहाँ Apache का नाम httpd है – package, service और log फ़ोल्डर /var/log/httpd/ सब httpd. सिर्फ़ Ubuntu पर apache2 है. किस OS पर हो, पहले cat /etc/os-release से देखो.
Where are the Apache files on Amazon Linux 2023?
| Item | Path / command |
|---|---|
| Package / service | httpd / httpd |
| Main config | /etc/httpd/conf/httpd.conf |
| Site configs | /etc/httpd/conf.d/*.conf |
| Default web root | /var/www/html |
| Apache user | apache |
| Logs | /var/log/httpd/access_log, /var/log/httpd/error_log |
| Config test | sudo apachectl configtest |
For a site in its own folder, create a virtual host in /etc/httpd/conf.d/mysite.conf:
sudo mkdir -p /var/www/mysite && echo "<h1>My site</h1>" | sudo tee /var/www/mysite/index.html
sudo tee /etc/httpd/conf.d/mysite.conf > /dev/null <<'VHOST'
<VirtualHost *:80>
ServerName mysite.local
DocumentRoot /var/www/mysite
<Directory /var/www/mysite>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/mysite_error.log
CustomLog /var/log/httpd/mysite_access.log combined
</VirtualHost>
VHOST
sudo apachectl configtest && sudo service httpd reload
With name-based virtual hosts, the first <VirtualHost *:80> loaded answers any request whose name does not match another vhost, so this one also answers requests to the public IP. Options -Indexes stops Apache from listing a folder that has no index file.
Ravindra Bagale's Tip
💡 Make sudo apachectl configtest && sudo service httpd reload a habit. If the test fails, the reload doesn't happen, so one typo cannot take your site down. And when an error appears, don't guess – read sudo tail -n 20 /var/log/httpd/error_log; the file and line number are right there.
Ravindra Bagale's Tip – मराठी
💡 sudo apachectl configtest && sudo service httpd reload ही एकच सवय लावा. टेस्ट फेल झाली तर reload होत नाही, म्हणून एका टायपो मुळे तुमची साइट बंद पडत नाही. आणि एरर आला की अंदाज लावू नका – sudo tail -n 20 /var/log/httpd/error_log वाचा, फाइल आणि लाइन नंबर तिथेच मिळतो.
Ravindra Bagale's Tip – हिंदी
💡 sudo apachectl configtest && sudo service httpd reload की एक ही आदत बनाओ. टेस्ट फेल हुआ तो reload नहीं होता, इसलिए एक टाइपो से आपकी साइट बंद नहीं पड़ती. और एरर आए तो अंदाज़ा मत लगाओ – sudo tail -n 20 /var/log/httpd/error_log पढ़ो, फ़ाइल और लाइन नंबर वहीं मिलता है.
How do I fix common Apache errors on EC2?
Ghabru naka 😅 — find your symptom in the first column:
| Symptom | Likely cause | Fix |
|---|---|---|
Unit apache2.service not found |
Wrong service name on Amazon Linux | Use httpd: sudo service httpd start |
| Browser spins, then timeout | Port 80 missing in the security group; no public IP; typed https:// |
Add inbound HTTP 80 from 0.0.0.0/0; use http:// |
| Connection refused | Apache is not running | sudo service httpd start; sudo service httpd status |
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 |
Nginx or another server already uses port 80 | sudo ss -tlnp | grep :80; sudo service nginx stop |
| 403 Forbidden | No index.html; wrong permissions |
Add index.html; folders 755, files 644 |
| Test page instead of your page | File not in /var/www/html or a vhost points elsewhere |
ls /var/www/html; check DocumentRoot |
| Config change has no effect | Forgot to reload, or a syntax error | sudo apachectl configtest && sudo service httpd reload |
On the older Amazon Linux 2 the install command is the same (sudo yum install -y httpd). On Ubuntu use sudo apt install -y apache2 and the apache2 service name.
Learn it properly
This guide is the short path. The free AWS course explains every step in depth, with labs:
Got it? On Amazon Linux, Apache means httpd – install, start, enable, configtest and port 80 in the security group. That's all! Your page is live now. If you want WordPress next, this same Apache will be useful.
समजलं का? Amazon Linux वर Apache म्हणजे httpd – install, start, enable, configtest आणि security group मध्ये पोर्ट 80. एवढंच! आता तुमचं पेज लाइव्ह आहे. पुढे WordPress लावायचं असेल तर हाच Apache कामाला येईल.
समझ आया? Amazon Linux पर Apache मतलब httpd – install, start, enable, configtest और security group में पोर्ट 80. बस इतना ही! अब आपका पेज लाइव है. आगे WordPress लगाना हो तो यही Apache काम आएगा.
Frequently asked questions
How do I install Apache on Amazon Linux 2023?
Run sudo yum install -y httpd, then sudo service httpd start and sudo systemctl enable httpd. On Amazon Linux the package and the service are called httpd, not apache2.
Why does "sudo service apache2 start" fail on Amazon Linux?
Because the service is named httpd on Amazon Linux, CentOS and RHEL. apache2 is the name on Ubuntu and Debian, so Amazon Linux answers Unit not found.
Where is the Apache web root on Amazon Linux 2023?
The default web root is /var/www/html. The main config is /etc/httpd/conf/httpd.conf, site configs go in /etc/httpd/conf.d/*.conf and the logs are in /var/log/httpd/.
How do I check the Apache configuration for errors?
Run sudo apachectl configtest. It should print Syntax OK. Apply changes with sudo apachectl configtest && sudo service httpd reload.
Can Apache and Nginx run on the same EC2 instance?
Not both on port 80. Only one program can listen on a port, so stop one (sudo service nginx stop) before starting the other, or move one of them to a different port.
Does Apache start automatically after installation?
No, not on Amazon Linux 2023 or CentOS Stream 9. Start it with sudo service httpd start and enable it for every boot with sudo systemctl enable httpd. On Ubuntu, apache2 starts by itself.