温馨提示×

ubuntu apache2怎样启动

小樊
40
2026-09-11 04:31:37
栏目: 智能运维

在 Ubuntu 上启动 Apache2(通常叫 apache2httpd 的服务名是 apache2)常见方法如下:

1. 使用 systemctl(推荐,Ubuntu 16.04+)

sudo systemctl start apache2

设置开机自启:

sudo systemctl enable apache2

查看状态:

sudo systemctl status apache2

2. 使用 service 命令(老方式,仍可用)

sudo service apache2 start

3. 重启 / 停止

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

4. 验证是否启动成功

浏览器访问:

http://localhost

或命令行:

curl http://localhost

如果看到 Apache 默认页面,说明启动成功。

常见问题

  • 端口被占用:检查 80 端口
    sudo netstat -tulnp | grep :80
    
  • 未安装 Apache2
    sudo apt update
    sudo apt install apache2
    

如果你是在 容器 / WSL / 特殊环境 里用,也可以告诉我,我可以给你对应方案。

0