Apache 在 CentOS 上启动失败是比较常见的问题,原因通常集中在端口冲突、权限问题、配置错误、SELinux、防火墙或模块问题等。下面按“最常见 → 排查方法 → 解决思路”给你一个系统排查指南。
不要只看 Failed,要看详细日志:
systemctl status httpd -l
journalctl -xe
Apache 错误日志:
cat /var/log/httpd/error_log
ss -lntp | grep ':80'
ss -lntp | grep ':443'
可能被占用:
解决:
systemctl stop nginx
# 或改端口
vi /etc/httpd/conf/httpd.conf
Listen 8080
测试配置:
httpd -t
常见错误:
DocumentRoot 路径不存在修复后:
systemctl restart httpd
查看是否被拒:
ausearch -m AVC -ts recent
临时关闭测试:
setenforce 0
systemctl start httpd
✅ 长期解决(推荐):
setsebool -P httpd_can_network_connect 1
restorecon -Rv /var/www
Apache 默认用户:
apacheapachechown -R apache:apache /var/www/html
chmod -R 755 /var/www
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
例如:
mod_ssl 没装但配置了 443查看:
httpd -M
rpm -qa | grep httpd
systemctl list-unit-files | grep httpd
httpd -t
systemctl status httpd -l
ss -lntp | grep 80
getenforce
cat /var/log/httpd/error_log
你可以把下面内容贴出来,我可以直接告诉你是哪一条导致启动失败:
systemctl status httpd -l 输出/var/log/httpd/error_log 最后 10–20 行cat /etc/redhat-release)我可以精确到具体行、具体配置。