在 Ubuntu 上安装 Apache2 非常简单,一般用 apt 包管理器即可。
sudo apt update
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2
看到 active (running) 就说明成功了。
sudo ufw allow 'Apache'
# 或
sudo ufw allow 80/tcp
打开浏览器访问:
http://服务器IP
看到 Apache2 Ubuntu Default Page 就说明安装成功。
sudo systemctl stop apache2 # 停止
sudo systemctl restart apache2 # 重启
sudo systemctl reload apache2 # 重新加载配置
/var/www/html/etc/apache2如果你是 Ubuntu 22.04 / 20.04 / 24.04,以上步骤都适用。
需要我教你 配置虚拟主机 或 搭建 PHP / HTTPS 吗?