在 Ubuntu 上 Apache(通常是 apache2)无法启动,原因有很多种。下面按最常见 → 较少见的顺序帮你排查。
sudo systemctl status apache2
或:
sudo journalctl -xe
再试启动并看详细错误:
sudo apache2ctl configtest
常见输出:
Syntax errorAddress already in usePermission denied症状:
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
排查:
sudo netstat -tulnp | grep ':80'
# 或
sudo ss -tulnp | grep ':80'
常见占用程序:
解决:
sudo systemctl stop nginx
/etc/apache2/ports.conf)症状:
AH00526: Syntax error on line XX of /etc/apache2/...
检查:
sudo apache2ctl configtest
常见错误:
DocumentRoot 路径不存在解决:
按提示修改对应配置文件(通常在 /etc/apache2/sites-enabled/)
比如:
*:80查看启用的站点:
ls /etc/apache2/sites-enabled/
临时排查:
sudo a2dissite *
sudo systemctl restart apache2
如果这样能启动,就是站点配置问题。
症状:
(13)Permission denied: AH00072
常见原因:
解决:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
dpkg -l | grep apache2
重装:
sudo apt remove --purge apache2
sudo apt install apache2
查看:
free -h
dmesg | tail
sudo apache2ctl configtest
sudo systemctl status apache2
sudo ss -tulnp | grep ':80'
sudo ls /etc/apache2/sites-enabled/
请把下面信息贴出来:
sudo systemctl status apache2 的输出sudo apache2ctl configtest 的输出lsb_release -a)我可以直接告诉你具体是哪一行出问题。