CentOS 上 Apache(通常是 httpd)报错的原因有很多,不同错误表现对应不同问题。下面我按最常见情况给你一个排查清单,你可以对照看是哪一种。
先看具体报错信息:
systemctl status httpd -l
journalctl -xe
tail -n 50 /var/log/httpd/error_log
报错类似:
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
原因:
解决:
netstat -tunlp | grep :80
# 或
ss -tunlp | grep :80
停掉冲突服务或改端口。
报错:
Permission denied: AH00035: access to / denied
即使权限是对的,也可能被 SELinux 拦。
查看:
getenforce
临时关闭测试:
setenforce 0
永久解决(推荐):
chcon -R -t httpd_sys_content_t /var/www/html
现象:
解决:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
报错:
AH00526: Syntax error on line xx of /etc/httpd/conf/httpd.conf
检查:
httpd -t
根据提示修正配置。
Apache 用户通常是 apache:
ps aux | grep httpd
确保:
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html
报错:
Cannot load modules/libphp.so
CentOS 8+/Stream 常见,因为默认用 PHP-FPM。
解决:
yum install php php-fpm
systemctl enable --now php-fpm
常见:
DocumentRoot 不存在ServerName 冲突检查:
httpd -S
如果你愿意,把下面信息发我:
cat /etc/redhat-release)httpd -v)我可以直接帮你定位到具体原因 ✅