Debian 上 Apache 报错的原因有很多,不能一概而论,通常需要看具体报错信息。下面我先给你一个常见原因清单 + 排查方法,你可以对照看是哪一种。
systemctl status apache2
或
journalctl -xeu apache2
tail -n 50 /var/log/apache2/error.log
报错类似:
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
原因:
解决:
ss -ltnp | grep ':80'
关掉冲突服务或改端口。
报错:
AH00526: Syntax error on line xx of /etc/apache2/...
常见错误:
>检查:
apache2ctl configtest
例如使用 rewrite 报错 404 或 500:
a2enmod rewrite
systemctl restart apache2
Debian 默认:
www-data解决:
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www
访问 .php 直接下载文件:
apt install libapache2-mod-php
a2enmod php
systemctl restart apache2
Debian 一般没 SELinux,但可能有 ufw:
ufw allow 80
ufw allow 443
请把以下任一内容贴出来:
systemctl status apache2 输出/var/log/apache2/error.log 报错我可以直接告诉你是哪一行配置或哪个服务的问题。