在 CentOS 上解决 Apache(httpd)报错,通常按下面这个思路来排查,基本都能定位问题。
systemctl status httpd
如果没启动:
systemctl start httpd
systemctl enable httpd
tail -n 50 /var/log/httpd/error_log
常见错误示例:
Permission deniedAddress already in useCannot load modulesPHP Fatal error报错示例:
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
解决:
netstat -tunlp | grep 80
或
ss -tunlp | grep 80
systemctl stop nginx
vi /etc/httpd/conf/httpd.conf
Listen 8080
报错示例:
(13)Permission denied: access to / denied
解决:
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html
如果是 SELinux 问题:
setenforce 0 # 临时关闭
永久关闭(不推荐):
vi /etc/selinux/config
SELINUX=disabled
测试配置:
httpd -t
报错示例:
Syntax error on line 45 of /etc/httpd/conf/httpd.conf
解决:
常见错误:
DocumentRoot 不存在ServerName 冲突检查:
ls /etc/httpd/conf.d/
测试:
httpd -t
如果 Apache 无法解析 PHP:
yum install php php-cli php-common
systemctl restart httpd
查看 PHP 模块:
httpd -M | grep php
firewall-cmd --list-ports
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
systemctl status httpd
journalctl -xe
tail -n 50 /var/log/httpd/error_log
httpd -t
你可以直接把 报错内容贴出来,例如:
error_log 中的几行我可以一步一步帮你定位 ✅