要准确判断 Debian 上 Apache2 报错的原因,需要看具体的报错信息。不过我可以给你一份最常见原因 + 对应排查方法的清单,你对照看看是哪一种。
sudo systemctl status apache2
sudo journalctl -xeu apache2
sudo tail -n 50 /var/log/apache2/error.log
报错示例
AH00498: Address already in use: AH00072: make_sock: could not bind to address [::]:80
原因
解决
sudo lsof -i :80
sudo systemctl stop nginx
sudo systemctl restart apache2
报错示例
AH00526: Syntax error on line XX of /etc/apache2/sites-enabled/xxx.conf
检查
sudo apache2ctl configtest
常见错误
</VirtualHost>报错示例
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included
解决
sudo a2enmod rewrite
sudo systemctl restart apache2
报错示例
Permission denied: AH00035: access to / denied
检查
ls -ld /var/www/html
修复示例
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
现象
.php 文件直接下载,不解析解决
sudo apt install libapache2-mod-php
sudo systemctl restart apache2
sudo a2dissite 000-default.conf
sudo a2ensite your-site.conf
如果你愿意,直接把下面任意一个贴出来,我可以精确定位:
systemctl status apache2 输出/var/log/apache2/error.log 报错我可以直接告诉你是哪一行配置或权限出了问题。