Ubuntu 下 Apache2 启动失败 的原因很多,常见原因和排查方法如下(按出现频率排序)。你可以一步步对照排查。
Apache 默认监听 80 / 443 端口。
sudo systemctl status apache2
常见错误:
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
sudo ss -lntp | grep ':80\|:443'
sudo systemctl stop nginx
sudo nano /etc/apache2/ports.conf
把 Listen 80 改成 Listen 8080
配置写错会导致 Apache 直接起不来。
sudo apache2ctl configtest
常见错误:
Syntax error on line 12 of /etc/apache2/sites-enabled/xxx.conf
sudo a2dissite xxx.conf
例如启用了不存在的模块。
sudo journalctl -xe
php 模块但 PHP 没装sudo a2enmod ssl
sudo a2enmod rewrite
Apache 无法访问网站目录。
AH00035: access to / denied
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
常见于新增站点后。
ls /etc/apache2/sites-enabled/
sudo a2dissite *
sudo systemctl restart apache2
# 1. 查看状态
sudo systemctl status apache2
# 2. 查看详细错误
sudo journalctl -xe
# 3. 检查配置语法
sudo apache2ctl configtest
# 4. 检查端口
sudo ss -lntp | grep 80
⚠️ 会清空配置
sudo apt remove --purge apache2 apache2-utils
sudo apt install apache2
请把以下信息发我(复制粘贴即可):
sudo systemctl status apache2
sudo apache2ctl configtest
sudo journalctl -xe | tail -30
我可以 精确告诉你是哪一行配置或哪个端口导致失败 ✅