在 CentOS 上调试 Apache(通常是 httpd 服务),可以从日志、配置、进程、端口、权限、模块几个方面入手。下面按常用且实用的顺序说明。
rpm -qa | grep httpd
# 或
which httpd
systemctl status httpd
systemctl start httpd
systemctl enable httpd
如果启动失败,直接看报错信息。
/var/log/httpd/error_log
/var/log/httpd/access_log
tail -f /var/log/httpd/error_log
常见错误示例:
Permission denied → 文件/目录权限问题Address already in use → 端口被占用Invalid command → 配置文件语法错误httpd -t
# 或
apachectl configtest
输出:
Syntax OK → 配置没问题httpd -S
可看到:
DocumentRootss -lntp | grep httpd
# 或
netstat -lntp | grep httpd
默认端口:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
查看是否被拒绝:
getenforce
查看 SELinux 拒绝日志:
tail -f /var/log/audit/audit.log | grep httpd
临时关闭测试:
setenforce 0
常见修复:
chcon -R -t httpd_sys_content_t /var/www/html
ls -l /var/www/html
推荐权限:
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html
如果放在 /home/user/public_html,需:
setsebool -P httpd_enable_homedirs on
httpd -S
示例:
<VirtualHost *:80>
ServerName test.example.com
DocumentRoot /var/www/test
</VirtualHost>
检查:
ServerName 是否正确DocumentRoot 是否存在编辑:
vi /etc/httpd/conf/httpd.conf
修改:
LogLevel debug
重启:
systemctl restart httpd
vi /etc/php.ini
display_errors = On
error_reporting = E_ALL
查看 PHP 日志:
/var/log/php-fpm/error.log
systemctl status httpd
journalctl -xe
httpd -t
httpd -S
tail -f /var/log/httpd/error_log
ss -lntp
getenforce
如果你能提供:
我可以给你更精确的调试方案。