Apache HTTP Server (commonly referred to as "Apache") is one of the most widely used web servers in the world. This guide explains how to install Apache on popular Linux distributions such as Ubuntu, Debian, CentOS, AlmaLinux, and Rocky Linux.
Requirements
- Root or sudo access to the server
- A Linux distribution (Ubuntu, Debian, CentOS, etc.)
- Internet connection
Installation Steps
For Ubuntu/Debian:
- Update package lists
sudo apt update - Install Apache
sudo apt install apache2 -y - Enable and start the Apache service
sudo systemctl enable apache2
sudo systemctl start apache2 - Check Apache status
sudo systemctl status apache2 - Test in browser
Visit your server's IP address in a web browser. You should see the Apache default page.
For CentOS/RHEL/AlmaLinux/Rocky Linux:
- Install Apache (httpd)
sudo yum install httpd -y - Enable and start the Apache service
sudo systemctl enable httpd
sudo systemctl start httpd - Check Apache status
sudo systemctl status httpd - Test in browser
Visit your server's IP address to view the Apache welcome page.
Common Apache Commands
- Restart Apache:
sudo systemctl restart apache2(Ubuntu/Debian)sudo systemctl restart httpd(CentOS/RHEL) - Reload configuration:
sudo systemctl reload apache2orhttpd - Test Apache configuration:
apachectl configtest
Default File Locations
- Configuration file:
/etc/apache2/apache2.conf(Ubuntu/Debian)/etc/httpd/conf/httpd.conf(CentOS/RHEL)
- Document root:
/var/www/html - Log files:
/var/log/apache2/or/var/log/httpd/
Opening Firewall (Optional)
If using UFW (Ubuntu):sudo ufw allow 'Apache Full'
If using firewalld (CentOS/RHEL):sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload