在 Ubuntu 上安装 Apache2 非常简单,通常只需要几步。下面给你最常用、最稳妥的方法(适用于 Ubuntu 20.04 / 22.04 / 24.04)。
sudo apt update
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
查看运行状态:
sudo systemctl status apache2
看到 active (running) 就说明成功了。
在浏览器中访问:
http://你的服务器IP
或本机:
http://localhost
如果看到 Apache2 Ubuntu Default Page,说明安装成功 ✅
# 停止
sudo systemctl stop apache2
# 重启
sudo systemctl restart apache2
# 重新加载配置(不中断服务)
sudo systemctl reload apache2
如果启用了 UFW:
sudo ufw allow 'Apache'
# 或
sudo ufw allow 80/tcp
默认网站根目录:
/var/www/html
你可以修改或替换 index.html 来部署自己的页面。
如果你是想:
可以继续告诉我你的使用场景,我一步一步帮你配。