温馨提示×

centos怎样开启apache2服务

小樊
39
2026-09-27 03:29:50
栏目: 智能运维

在 CentOS 里,Apache 的软件包名通常不是 apache2(那是 Debian/Ubuntu 的叫法),而是 httpd。下面分情况说明。


一、CentOS 6 及更早版本(SysVinit)

# 启动 Apache
service httpd start

# 设置开机自启
chkconfig httpd on

# 查看状态
service httpd status

二、CentOS 7 / 8 / Stream(systemd,最常见)

# 启动 Apache
systemctl start httpd

# 设置开机自启
systemctl enable httpd

# 查看运行状态
systemctl status httpd

# 重启 Apache
systemctl restart httpd

三、如果还没安装 Apache

# CentOS 7/8
yum install httpd -y
# 或
dnf install httpd -y

安装后再执行上面的 systemctl 命令。


四、防火墙放行(很重要)

如果开了 firewalld:

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

如果是 iptables(老系统):

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save

五、验证是否成功

浏览器访问服务器 IP:

http://服务器IP

看到 Apache 测试页 就说明成功了。


如果你用的是 CentOS 特定版本 或 面板(如宝塔),可以告诉我,我给你更精确的命令。

0 踩