Check Error Messages
sudo systemctl status apache2
sudo journalctl -u apache2 -f
sudo apache2ctl configtest # Test configuration
Common Configuration Errors
1. Syntax Errors
apache2ctl configtest shows line numbers:
AH00526: Syntax error on line 10 of /etc/apache2/sites-enabled/000-default.conf
Fix the specific line.
2. Port Already in Use
sudo netstat -tlnp | grep :80
sudo lsof -i :80
# Stop conflicting service
sudo systemctl stop nginx
3. Missing DocumentRoot
# Ensure directory exists
sudo mkdir -p /var/www/html
4. Permission Issues on Logs/Pids
sudo chown -R www-data:www-data /var/log/apache2
sudo rm /var/run/apache2/apache2.pid
5. Module Conflicts
# Disable conflicting modules
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
sudo systemctl restart apache2
6. SELinux Blocking (CentOS/RHEL)
getenforce
sudo setenforce 0 # Test only
sudo restorecon -Rv /etc/apache2
Check Apache Error Log
sudo tail -f /var/log/apache2/error.log
Reinstall Apache
# Ubuntu/Debian
sudo apt purge apache2 -y
sudo apt install apache2 -y