在 Ubuntu 上排查 Apache2 错误,通常可以按下面几个步骤来:
Apache 默认错误日志位置:
sudo tail -f /var/log/apache2/error.log
查看最近 50 行:
sudo tail -n 50 /var/log/apache2/error.log
如果是虚拟主机(vhost),可能单独有日志:
sudo ls /var/log/apache2/
sudo tail -f /var/log/apache2/access.log
可用来判断请求是否到达 Apache。
sudo apache2ctl configtest
或:
sudo apache2 -t
如果有错误,会提示具体文件和行号。
systemctl status apache2
如果没启动:
sudo systemctl start apache2
sudo systemctl enable apache2
重启 Apache:
sudo systemctl restart apache2
编辑站点配置或全局配置:
sudo nano /etc/apache2/apache2.conf
确保有:
LogLevel warn
调试时可临时改为:
LogLevel debug
然后重启:
sudo systemctl restart apache2
PHP 错误通常在:
/var/log/apache2/error.log
或 php.ini 中开启:
display_errors = On
error_reporting = E_ALL
journalctl -u apache2
端口被占用:
sudo netstat -tulnp | grep :80
| 现象 | 可能原因 |
|---|---|
| 403 Forbidden | 权限 / DocumentRoot 配置 |
| 404 Not Found | 路径或 Rewrite 错误 |
| 500 Internal | PHP / .htaccess 错误 |
| 无法启动 | 端口占用 / 配置错误 |
如果你愿意,可以把 具体报错内容 或 error.log 的片段贴出来,我可以帮你精确定位问题。