Ubuntu 上 Apache 启动不了,常见原因和排查方法如下(一步一步来,基本都能定位):
sudo systemctl status apache2
或
sudo apache2ctl configtest
常见提示和含义:
Address already in use → 端口被占用Syntax error → 配置文件写错permission denied → 权限问题sudo netstat -tulnp | grep ':80\|:443'
常见占用者:
解决:
sudo systemctl stop nginx
或修改 Apache 端口:
sudo nano /etc/apache2/ports.conf
sudo apache2ctl configtest
如果有错误,会指出文件和第几行。
比如:
DocumentRoot 路径不存在Directory 权限检查:
ls /etc/apache2/sites-enabled/
临时排除:
sudo a2dissite xxx.conf
sudo systemctl restart apache2
Apache 默认用户是 www-data
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
sudo apache2ctl -t
错误如:
SSLCertificateFile: file does not exist
解决:
sudo apt update
sudo apt install --reinstall apache2
sudo tail -n 50 /var/log/apache2/error.log
systemctl status apache2apache2ctl configtest如果你愿意,把下面两条命令的输出贴出来,我可以直接帮你定位:
sudo systemctl status apache2
sudo apache2ctl configtest