在 Ubuntu 上排查 Apache2(apache2) 错误,通常可以按下面步骤系统地进行。
systemctl status apache2
或
service apache2 status
常见状态:
active (running):正常failed:启动失败(看报错)inactive:未启动尝试启动 / 重启:
sudo systemctl start apache2
sudo systemctl restart apache2
Apache 错误通常都在这里:
sudo tail -n 50 /var/log/apache2/error.log
实时查看:
sudo tail -f /var/log/apache2/error.log
访问日志(看请求是否到达):
sudo tail -n 50 /var/log/apache2/access.log
sudo apache2ctl configtest
或
apache2ctl -t
常见错误:
Syntax errorCould not open configuration fileInvalid commandApache 默认用 80 / 443。
查看端口:
sudo netstat -tulnp | grep ':80'
# 或
sudo ss -tulnp | grep ':80'
如果被 nginx / 其他程序占用:
sudo systemctl stop nginx
查看已启用站点:
ls /etc/apache2/sites-enabled/
检查具体配置:
sudo nano /etc/apache2/sites-enabled/000-default.conf
常见错误:
DocumentRoot 路径不存在Apache 默认用户是 www-data
查看:
ps aux | grep apache
修复权限示例:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
SELinux(Ubuntu 默认未启用,可忽略)
查看已启用模块:
apache2ctl -M
启用模块示例:
sudo a2enmod rewrite
sudo systemctl restart apache2
禁用模块:
sudo a2dismod 模块名
sudo ufw status
允许 Web:
sudo ufw allow 'Apache Full'
/var/log/apache2/error.log
storage/logs)✅ systemctl status apache2
✅ apache2ctl configtest
✅ tail error.log
✅ 端口是否被占用
✅ 虚拟主机配置是否正确
✅ 文件权限是否为 www-data
如果你愿意,可以把 具体报错信息(终端或 error.log)发出来,我可以帮你精准定位。