在 Ubuntu 上排查 Apache2 问题,通常可以按照下面这个“由浅入深”的流程来做。
systemctl status apache2
常见状态:
active (running) ✅ 正常inactive (dead) ❌ 没启动failed ❌ 启动失败启动 / 重启:
sudo systemctl start apache2
sudo systemctl restart apache2
sudo tail -n 50 /var/log/apache2/error.log
常见错误:
sudo apache2ctl configtest
输出:
Syntax OK ✅修复后:
sudo systemctl reload apache2
sudo ss -tulnp | grep :80
# 或
sudo netstat -tulnp | grep apache
如果 80 端口被 nginx / 其他程序占用:
sudo lsof -i :80
列出已启用站点:
ls /etc/apache2/sites-enabled/
测试某个站点配置:
sudo apache2ctl -S
常见问题:
chmod / chown)网站目录建议权限:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
SELinux 在 Ubuntu 一般关闭,不用管。
查看已启用模块:
apache2ctl -M
启用模块(如 rewrite):
sudo a2enmod rewrite
sudo systemctl restart apache2
检查:
php -v
sudo a2enmod php8.1 # 根据实际版本
sudo systemctl restart apache2
测试:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
访问:http://服务器IP/info.php
sudo ufw status
允许 HTTP:
sudo ufw allow 80
sudo ufw allow 443
systemctl status apache2apache2ctl configtesttail /var/log/apache2/error.log如果你愿意,可以把 具体报错信息 或 你想实现的功能(比如 HTTPS、反向代理、WordPress)发出来,我可以直接帮你定位问题。