在 CentOS 上“修复 Apache”通常取决于具体症状(起不来、报错、配置错误、权限问题等)。下面按常见场景 + 通用修复流程给你一套实用方案。
systemctl status httpd
或
service httpd status
如果无法启动,先看错误:
journalctl -xe
# 或
systemctl status httpd -l
httpd -t
或
apachectl configtest
常见错误:
AH00526: Syntax errorDocumentRoot must be a directory根据提示修正 /etc/httpd/conf/httpd.conf 或相关 conf.d/*.conf
ss -lntp | grep ':80'
如果有 nginx / 其他程序:
systemctl stop nginx
或修改 Apache 端口:
Listen 8080
确保:
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html
SELinux 常见问题(CentOS 默认开启):
ls -Z /var/www/html
restorecon -Rv /var/www/html
临时测试(不推荐长期关闭):
setenforce 0
查看加载模块:
httpd -M
如需启用:
vim /etc/httpd/conf.modules.d/00-base.conf
取消注释对应 LoadModule
在 httpd.conf 或 conf.d/*.conf 中确认:
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Require all granted
</Directory>
yum remove httpd -y
yum install httpd -y
systemctl enable httpd
systemctl start httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
/var/log/httpd/error_log
/var/log/httpd/access_log
如果你方便,直接贴出:
systemctl status httpd 输出httpd -t 报错我可以精准帮你修,不用重装。