可以从 命令行 和 浏览器 两个层面来确认 Apache2 在 Ubuntu 上是否安装并运行成功。
apache2 -v
✅ 成功示例:
Server version: Apache/2.4.52 (Ubuntu)
sudo systemctl status apache2
✅ 正常状态应看到:
Active: active (running)
如果未启动:
sudo systemctl start apache2
sudo systemctl enable apache2
ss -lntp | grep 80
或
sudo netstat -lntp | grep 80
✅ 应该看到类似:
LISTEN 0 128 0.0.0.0:80
curl http://localhost
✅ 看到 HTML 内容(包含 Apache2 Ubuntu Default Page)说明成功。
打开:
http://localhost
或
http://127.0.0.1
✅ 看到 Apache 默认欢迎页即成功。
在另一台电脑浏览器访问:
http://服务器IP
⚠️ 如果访问不了,常见原因:
sudo ufw allow 80/tcp
sudo ufw reload
sudo apache2ctl configtest
✅ 正常输出:
Syntax OK
| 问题 | 解决方法 |
|---|---|
| 服务起不来 | journalctl -xe 查看详细错误 |
| 403 Forbidden | 检查 /var/www/html 权限 |
| 404 | 确认 index.html 是否存在 |
| 端口被占用 | sudo lsof -i:80 |
apache2 -v
sudo systemctl status apache2
curl http://localhost
如果你愿意,可以把 systemctl status apache2 的输出或报错贴出来,我可以帮你具体排查。