在 Debian 上 Apache 启动失败,常见原因和排查方法如下(按出现频率排序):
sudo systemctl status apache2
sudo journalctl -xeu apache2
sudo apache2ctl configtest
configtest 能直接告诉你配置文件哪里错。
错误示例
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
排查
sudo ss -tulnp | grep ':80'
可能是:
解决
sudo fuser -k 80/tcp
sudo systemctl restart apache2
或修改监听端口:
Listen 8080
错误示例
AH00526: Syntax error on line 12 of /etc/apache2/sites-enabled/xxx.conf
解决
sudo apache2ctl configtest
根据提示修改对应文件。
*:80ServerName 重复DocumentRoot检查
ls /etc/apache2/sites-enabled/
sudo a2enmod
sudo a2dismod php7.4
sudo a2enmod php8.2
www-data 无权访问的路径sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
sudo systemctl unmask apache2
sudo systemctl enable apache2
sudo aa-status
configtest 无报错如果你愿意,可以把下面命令的输出贴出来,我可以直接帮你定位:
sudo systemctl status apache2
sudo apache2ctl configtest