在 Debian 系统上调试 Apache(通常是 Apache2)错误,可以按下面步骤系统排查,从日志 → 配置 → 权限 → 模块 → 运行环境逐步定位问题。
sudo tail -f /var/log/apache2/error.log
或查看完整内容:
sudo less /var/log/apache2/error.log
常见错误示例:
Permission deniedFile does not existAH00558: Could not reliably determine the server's fully qualified domain nameAddress already in use如果你使用了虚拟主机:
sudo tail -f /var/log/apache2/你的站点-error.log
sudo apache2ctl configtest
或:
sudo apache2 -t
✅ 返回:
Syntax OK
❌ 常见错误:
ls /etc/apache2/sites-enabled/
ls /etc/apache2/sites-available/
启用站点:
sudo a2ensite 你的站点.conf
sudo systemctl reload apache2
sudo systemctl status apache2
启动 / 重启:
sudo systemctl start apache2
sudo systemctl restart apache2
如果启动失败,错误信息通常就在 status 输出中
sudo ss -lntp | grep 80
如果 80 端口被 nginx 或其他程序占用:
sudo systemctl stop nginx
curl -I http://localhost
ls -ld /var/www/html
推荐权限:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
⚠️ 不要随意设为 777
Debian 一般不用 SELinux,但如果你启用过:
getenforce
apache2ctl -M
sudo a2enmod rewrite
sudo systemctl restart apache2
常见模块错误:
.htaccess 不生效 → 没启用 AllowOverridephp 模块未启用sudo apt install libapache2-mod-php
sudo a2enmod php
echo "<?php phpinfo();" | sudo tee /var/www/html/info.php
访问:
http://服务器IP/info.php
sudo nano /etc/php/*/apache2/php.ini
设置:
display_errors = On
error_reporting = E_ALL
重启 Apache:
sudo systemctl restart apache2
✅ 看错误日志
✅ apache2ctl configtest
✅ systemctl status apache2
✅ 端口是否被占用
✅ 目录权限
✅ 虚拟主机配置
✅ 模块是否启用
你可以直接贴出:
/var/log/apache2/error.log 的报错我可以一步步帮你分析 ✅