在 Debian 上排错 Apache(通常是 Apache2),可以按下面一套“从外到内”的思路来查。我分 常见现象 → 排查步骤 → 常用命令 来说。
systemctl status apache2
常见状态:
active (running):服务正常failed:启动失败(看日志)inactive:没启动启动 / 重启:
sudo systemctl start apache2
sudo systemctl restart apache2
sudo systemctl enable apache2
sudo ss -tulnp | grep apache
# 或
sudo netstat -tulnp | grep apache
Apache 默认:
如果没有监听:
ports.confsudo ufw status
放行:
sudo ufw allow 80
sudo ufw allow 443
云服务器还要看 安全组。
sudo apache2ctl configtest
常见错误:
AH00526: Syntax errorDocumentRoot does not existSSLCertificateFile not found站点配置在:
/etc/apache2/sites-available/
/etc/apache2/sites-enabled/
启用 / 禁用:
sudo a2ensite example.conf
sudo a2dissite example.conf
注意:
sites-enabled 里只是软链接restartsudo tail -f /var/log/apache2/error.log
常见错误:
Permission deniedclient denied by server configurationPHP Fatal errorsudo tail -f /var/log/apache2/access.log
用来判断:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
<Directory /var/www/html>
Require all granted
</Directory>
查看已启用模块:
sudo apache2ctl -M
启用模块:
sudo a2enmod rewrite
sudo systemctl restart apache2
PHP 常见:
sudo a2enmod php8.2
sudo apache2ctl configtest
常见:
systemctl status apache2apache2ctl configtesttail -f /var/log/apache2/error.logss -tulnp | grep 80如果你愿意,可以把 具体报错信息(终端输出 / error.log / 浏览器状态码)贴出来,我可以直接帮你定位。