Apache HTTP Server Installation
This guide covers the essential steps to install and start Apache (httpd) on Debian/Ubuntu and CentOS systems.
Installation Steps
- Debian/Ubuntu
- CentOS
1. Update Package Index
sudo apt update
2. Install Apache
sudo apt install apache2 -y
3. Start and Enable Apache
sudo systemctl start apache2
sudo systemctl enable apache2
4. Check Status
sudo systemctl status apache2
5. Allow HTTP/HTTPS in Firewall (if UFW is enabled)
sudo ufw allow 'Apache Full'
6. Test in Browser
Visit: http://localhost or your server's IP address.
1. Update Package Index
sudo yum update -y
2. Install Apache (httpd)
sudo yum install httpd -y
3. Start and Enable Apache
sudo systemctl start httpd
sudo systemctl enable httpd
4. Check Status
sudo systemctl status httpd
5. Allow HTTP/HTTPS in Firewall (if firewalld is enabled)
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
6. Test in Browser
Visit: http://localhost or your server's IP address.
Uninstall Apache
- Debian/Ubuntu
- CentOS
sudo apt remove --purge apache2 -y
sudo apt autoremove -y
sudo yum remove httpd -y
Quick Commands Reference
- Debian/Ubuntu
- CentOS
| Task | Command |
|---|---|
| Start Apache | sudo systemctl start apache2 |
| Stop Apache | sudo systemctl stop apache2 |
| Restart Apache | sudo systemctl restart apache2 |
| Enable on Boot | sudo systemctl enable apache2 |
| Status | sudo systemctl status apache2 |
| Task | Command |
|---|---|
| Start Apache | sudo systemctl start httpd |
| Stop Apache | sudo systemctl stop httpd |
| Restart Apache | sudo systemctl restart httpd |
| Enable on Boot | sudo systemctl enable httpd |
| Status | sudo systemctl status httpd |
Tip: Default web root is /var/www/html.