在 Ubuntu 上安装 Apache 非常简单,通常只需几步即可完成。下面以 Ubuntu 20.04 / 22.04 / 24.04 为例说明。
sudo apt update
(可选)
sudo apt upgrade
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
查看状态:
sudo systemctl status apache2
看到 active (running) 就说明成功了。
在浏览器中访问:
http://localhost
或服务器 IP:
http://你的服务器IP
看到 Apache2 Ubuntu Default Page 即表示成功。
sudo systemctl stop apache2 # 停止
sudo systemctl restart apache2 # 重启
sudo systemctl reload apache2 # 重新加载配置
sudo ufw allow 'Apache'
# 或
sudo ufw allow 80/tcp
/var/www/html
/etc/apache2/
sudo apt install php libapache2-mod-php -y
sudo systemctl restart apache2
如果你是要 搭建网站 / 配置虚拟主机 / 使用 HTTPS,可以告诉我具体需求,我可以进一步指导。