Ubuntu 上 Apache 启动失败的原因有很多,下面先给你最常见的原因和排查方法,你可以一步步来定位。
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 [::]:80
解决
sudo netstat -tulnp | grep :80
常见占用程序:
关闭冲突服务:
sudo systemctl stop nginx
或修改 Apache 端口:
sudo nano /etc/apache2/ports.conf
改 Listen 80 → Listen 8080
错误示例
AH00526: Syntax error on line 10 of /etc/apache2/sites-enabled/xxx.conf
解决
sudo apache2ctl configtest
根据提示修正配置文件,然后:
sudo systemctl restart apache2
常见错误:
DocumentRoot 路径不存在<VirtualHost> 写错检查:
ls /var/www/你的目录
错误示例
Permission denied: AH00035
解决
sudo chown -R www-data:www-data /var/www
sudo chmod -R 755 /var/www
常见于:
检查:
sudo apache2ctl -t
which apache2
如果没有:
sudo apt update
sudo apt install apache2
configtest 无报错你可以把下面两条命令的输出发给我,我可以直接帮你判断原因:
sudo systemctl status apache2
sudo apache2ctl configtest
这样能更快定位问题。