在 CentOS 上排查 Apache(httpd)故障,通常可以按下面系统化步骤来进行,从“能不能启动”到“为什么报错”逐步定位。
systemctl status httpd
或(老版本):
service httpd status
常见状态:
active (running):服务正常failed:启动失败(看下文日志)inactive:未启动尝试启动:
systemctl start httpd
若失败,直接看错误:
systemctl status httpd -l
journalctl -xe
CentOS 默认:
/var/log/httpd/error_log
实时查看:
tail -f /var/log/httpd/error_log
/var/log/httpd/access_log
httpd -t
或:
apachectl configtest
常见错误:
ss -lntp | grep :80
# 或
netstat -lntp | grep httpd
如果被 nginx 占用:
systemctl stop nginx
firewall-cmd --list-all
放行 80/443:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
查看是否开启:
getenforce
临时关闭测试:
setenforce 0
若关闭后正常 → SELinux 权限问题:
ls -Z /var/www/html
restorecon -Rv /var/www/html
Apache 默认用户:
ps aux | grep httpd
# 通常是 apache
目录示例:
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html
查看虚拟主机:
httpd -S
检查:
<Directory> 是否允许访问查看已加载模块:
httpd -M
PHP 不解析:
yum install php php-cli
systemctl restart httpd
✅ 服务是否启动
✅ 错误日志内容
✅ 配置语法是否正确
✅ 端口是否被占用
✅ 防火墙 / SELinux
✅ 目录权限
✅ 虚拟主机配置
如果你愿意,可以把 具体报错信息或 error_log 内容贴出来,我可以直接帮你定位是哪一类问题。