Ubuntu 下 Apache 报错很常见,要“解决”通常要先看具体报错信息。我分阶段给你一个排查思路 + 常用解决办法,你可以对照着来。
sudo tail -n 50 /var/log/apache2/error.log
sudo apache2ctl configtest
常见输出:
Syntax OK → 配置没问题AH00558 / AH00526 → 配置文件有错误报错示例:
(98)Address already in use: AH00072: make_sock: could not bind to address
解决:
sudo netstat -tulnp | grep :80
常见占用程序:nginx、另一个 apache、docker
关闭冲突服务:
sudo systemctl stop nginx
sudo a2ensite 000-default.conf
sudo systemctl reload apache2
报错示例:
Invalid command 'php_admin_value'
解决:
sudo apt install libapache2-mod-php
sudo a2enmod php
sudo systemctl restart apache2
报错:
AH01630: client denied by server configuration
解决:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
并确认:
<Directory /var/www/html>
Require all granted
</Directory>
sudo a2enmod ssl
sudo a2ensite default-ssl.conf
证书路径必须正确。
sudo systemctl status apache2
sudo systemctl restart apache2
sudo systemctl enable apache2
如果你愿意,可以把下面任意一个内容贴给我:
error.log 中的报错configtest 的输出我可以直接帮你定位并给出精准命令。