温馨提示×

Ubuntu Apache如何停止

小樊
53
2026-08-27 14:17:55
栏目: 智能运维

在 Ubuntu 上停止 Apache 服务,常用以下几种方式(适用于 Apache 2,Ubuntu 16.04+):


✅ 推荐方式(使用 systemctl)

sudo systemctl stop apache2

查看状态

sudo systemctl status apache2

✅ 旧版方式(使用 service,仍可用)

sudo service apache2 stop

✅ 彻底停止并禁止开机启动

sudo systemctl stop apache2
sudo systemctl disable apache2

查看是否已禁用:

systemctl is-enabled apache2

✅ 只停止监听端口(不推荐)

sudo apachectl stop

需要确认 apachectl 在 PATH 中,且权限足够


✅ 验证 Apache 是否已停止

ss -tlnp | grep :80
# 或
curl -I http://localhost

✅ 常见错误

❌ 端口被占用 / 无法停止

sudo lsof -i :80
sudo kill -9 <PID>

✅ 总结

需求 命令
停止 Apache sudo systemctl stop apache2
禁止开机启动 sudo systemctl disable apache2
查看状态 systemctl status apache2

如果你是想 临时关闭测试重启 Apache完全卸载 Apache,可以告诉我具体场景,我可以给你更合适的方案。

0