Ubuntu 上 Apache2 启动失败 常见原因很多,下面按「最常见 → 较少见」给你一个排查清单,基本能定位 90% 的问题。
sudo systemctl status apache2
sudo journalctl -xe
sudo apache2ctl configtest
重点看:
Job for apache2.service failed(98)Address already in useSyntax error on line xxApache 默认用 80 / 443
查看占用:
sudo netstat -tulnp | grep ':80\|:443'
# 或
sudo ss -tulnp | grep ':80\|:443'
常见“凶手”:
解决:
sudo nano /etc/apache2/ports.conf
sudo apache2ctl configtest
常见错误:
</VirtualHost>两个站点都监听 80 端口且 ServerName 相同
检查:
ls /etc/apache2/sites-enabled/
临时关闭站点测试:
sudo a2dissite xxx.conf
sudo systemctl restart apache2
比如启用了不存在的模块
sudo a2enmod
或:
sudo apache2ctl -M
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
ports.conf 里写了不存在的 IP:
Listen 192.168.1.100:80
但机器没有这个 IP → 启动失败
sudo apache2ctl configtest
sudo systemctl restart apache2
sudo systemctl status apache2
你可以直接把下面内容贴出来,我帮你精准判断:
sudo systemctl status apache2
sudo apache2ctl configtest
或者贴出报错截图 / 日志片段即可。