温馨提示×

怎样开启ubuntu apache2

小樊
52
2026-09-11 04:36:40
栏目: 智能运维

在 Ubuntu 上开启(启动)Apache2,通常涉及安装 → 启动 → 设置开机自启 → 验证几个步骤。下面按常见情况说明。


一、如果还没安装 Apache2

sudo apt update
sudo apt install apache2

安装完成后,Apache2 一般会自动启动。


二、启动 Apache2

1. 使用 systemd(Ubuntu 16.04 及以后)

sudo systemctl start apache2

检查状态:

sudo systemctl status apache2

看到 active (running) 就说明已开启。


三、设置开机自动启动

sudo systemctl enable apache2

(如果想取消开机启动:sudo systemctl disable apache2


四、重启 / 停止 Apache2

sudo systemctl restart apache2   # 重启
sudo systemctl stop apache2      # 停止

五、验证是否成功

在浏览器访问:

http://localhost

或服务器 IP:

http://你的服务器IP

看到 Apache2 Ubuntu Default Page 就说明成功了。


六、常见问题

1. 端口被占用(如 Nginx)

sudo netstat -tulnp | grep :80

2. 防火墙未放行

sudo ufw allow 80
sudo ufw allow 443

3. 旧版本命令(不推荐但可用)

sudo service apache2 start

如果你是想开启 HTTPS、虚拟主机、或某个站点不生效,可以告诉我具体场景,我可以进一步帮你配置。

0