Ubuntu 上 Apache 启动失败的原因很多,下面按最常见 → 次常见给你排查思路和命令,基本能定位 90% 的问题。
sudo systemctl status apache2
sudo journalctl -xeu apache2
或者直接看启动报错:
sudo apache2ctl configtest
常见输出和含义:
(98)Address already in use → 端口被占用Syntax error → 配置文件写错Failed to enable APR → 模块或权限问题sudo netstat -tulnp | grep ':80'
常见占用者:
解决:
sudo systemctl stop nginx
# 或修改端口
sudo nano /etc/apache2/ports.conf
sudo apache2ctl configtest
如果有:
AH00526: Syntax error
按提示修改对应文件,通常在:
/etc/apache2/apache2.conf/etc/apache2/sites-enabled/比如两个站点都监听 80:
<VirtualHost *:80>
解决:
ServerName 不重复sudo rm /etc/apache2/sites-enabled/xxx.conf
比如启用了 ssl 但没证书:
sudo a2dismod ssl
sudo systemctl restart apache2
/home 目录但 Apache 无权访问sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
df -h
free -m
sudo apache2ctl configtest
sudo systemctl restart apache2
sudo systemctl status apache2
systemctl status apache2 输出apache2ctl configtest 输出你可以把报错直接贴出来,我帮你一行行看。