在 Debian 上用 Apache(通常是 apache2)时,排错的核心就是看日志 + 查配置。下面按“从快到慢、从常见到深入”的思路给你一个实用排错流程。
systemctl status apache2
如果没启动:
sudo systemctl start apache2
sudo systemctl enable apache2
启动失败常用:
sudo apache2ctl configtest
会直接告诉你配置文件哪一行有语法错误
/var/log/apache2/error.log
实时查看:
sudo tail -f /var/log/apache2/error.log
常见错误示例:
Permission denied → 文件/目录权限问题AH00558 → 配置文件警告client denied by server configuration → 访问权限(Require all granted)/var/log/apache2/access.log
看:
原因通常是:
Require all granted检查配置:
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
权限检查:
ls -ld /var/www/html
ls -l /var/www/html/index.html
apache2ctl -S
查看虚拟主机和 DocumentRoot
常见:
.htaccess 语法错误看 error.log:
sudo tail -n 50 /var/log/apache2/error.log
如果是 PHP:
sudo tail -f /var/log/php*-fpm.log
sudo ss -tulnp | grep :80
常见冲突:
列出启用的站点:
ls /etc/apache2/sites-enabled/
测试配置:
sudo apache2ctl -S
重载配置(不改端口):
sudo systemctl reload apache2
在虚拟主机或全局加:
LogLevel alert rewrite:trace3
然后:
sudo systemctl reload apache2
tail -f /var/log/apache2/error.log
⚠️ 调试完记得改回:
LogLevel warn
systemctl status apache2apache2ctl configtesttail -f /var/log/apache2/error.log如果你愿意,可以把:
error.log 相关几行贴出来,我可以直接帮你定位。