在 Ubuntu 上开启(启动)Apache2,通常涉及安装 → 启动 → 设置开机自启 → 验证几个步骤。下面按常见情况说明。
sudo apt update
sudo apt install apache2
安装完成后,Apache2 一般会自动启动。
sudo systemctl start apache2
检查状态:
sudo systemctl status apache2
看到 active (running) 就说明已开启。
sudo systemctl enable apache2
(如果想取消开机启动:sudo systemctl disable apache2)
sudo systemctl restart apache2 # 重启
sudo systemctl stop apache2 # 停止
在浏览器访问:
http://localhost
或服务器 IP:
http://你的服务器IP
看到 Apache2 Ubuntu Default Page 就说明成功了。
sudo netstat -tulnp | grep :80
sudo ufw allow 80
sudo ufw allow 443
sudo service apache2 start
如果你是想开启 HTTPS、虚拟主机、或某个站点不生效,可以告诉我具体场景,我可以进一步帮你配置。