温馨提示×

怎样启动centos apache2

小樊
45
2026-10-03 00:19:15
栏目: 智能运维

在 CentOS 里,Apache 的软件包名不是 apache2(那是 Ubuntu/Debian 的叫法),而是 httpd。下面是在 CentOS 上启动 Apache 的正确方法。


一、确认是否安装了 Apache(httpd)

rpm -q httpd

如果没有安装,先安装:

sudo yum install httpd -y
# CentOS 8 及以上
sudo dnf install httpd -y

二、启动 Apache(httpd)

sudo systemctl start httpd

三、设置开机自启(推荐)

sudo systemctl enable httpd

四、查看运行状态

sudo systemctl status httpd

看到 active (running) 说明启动成功。


五、防火墙放行 80 端口(重要)

如果无法访问网页,通常是防火墙没开:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

(如需 HTTPS)

sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

六、测试访问

浏览器访问:

http://服务器IP

看到 Apache Test Page 即成功。


常见命令总结

功能 命令
启动 systemctl start httpd
停止 systemctl stop httpd
重启 systemctl restart httpd
状态 systemctl status httpd
开机自启 systemctl enable httpd

如果你是从 Ubuntu 迁移到 CentOS,或者想用 apache2 命令,我也可以帮你对比说明。

0 踩