CentOS 上 Apache(httpd)日志报错 的原因非常多,需要看具体报错内容才能准确判断。下面我按常见错误类型 + 日志位置 + 排查方法给你一个系统性的说明,你可以对照自己的情况。
CentOS 7/8 常用:
# 错误日志(最重要)
/var/log/httpd/error_log
# 访问日志
/var/log/httpd/access_log
如果你用的是 mod_ssl,还会有:
/var/log/httpd/ssl_error_log
日志示例:
(13)Permission denied: access to /index.html denied
原因:
解决方法:
# 目录权限
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html
# SELinux(非常重要)
setsebool -P httpd_can_network_connect 1
chcon -R -t httpd_sys_content_t /var/www/html
日志示例:
(98)Address already in use: AH00072: make_sock: could not bind to address
原因:
排查:
ss -lntp | grep :80
日志示例:
AH00526: Syntax error on line 12 of xxx.conf
解决:
httpd -t
根据提示修改配置文件。
日志示例:
AH00112: DocumentRoot [/www/html] does not exist
原因:
解决:
mkdir -p /www/html
典型现象:
验证:
getenforce
如果是 Enforcing,基本就是 SELinux 问题。
示例:
PHP Fatal error: Allowed memory size exhausted
解决:
vi /etc/php.ini
# 修改
memory_limit = 256M
systemctl restart httpd
# 1. 看错误日志
tail -n 50 /var/log/httpd/error_log
# 2. 检查配置
httpd -t
# 3. 检查端口
ss -lntp | grep httpd
# 4. 检查 SELinux
getenforce
请把以下信息发我:
cat /etc/redhat-release)httpd -v)getenforce)我可以直接告诉你是哪一行配置或权限导致的问题。