温馨提示×

apache centos如何启动

小樊
41
2026-09-18 02:48:15
栏目: 智能运维

CentOS 上启动 Apache(httpd) 通常有以下几种方式,取决于你使用的 CentOS 版本(CentOS 6 用 service,CentOS 7+ 用 systemctl)。


一、CentOS 7 / 8 / Stream(推荐)

1️⃣ 启动 Apache

sudo systemctl start httpd

2️⃣ 设置开机自启

sudo systemctl enable httpd

3️⃣ 查看运行状态

sudo systemctl status httpd

4️⃣ 停止 / 重启

sudo systemctl stop httpd
sudo systemctl restart httpd

二、CentOS 6(老版本)

sudo service httpd start
sudo chkconfig httpd on

三、防火墙(非常重要)

如果启动后浏览器访问不了,通常是防火墙没放行 80 端口。

1️⃣ firewalld(CentOS 7+)

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

2️⃣ iptables(CentOS 6)

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

四、验证是否启动成功

浏览器访问:

http://服务器IP

看到 Apache 测试页 即成功。


五、常见问题

❌ 端口被占用

sudo netstat -tunlp | grep :80

❌ Apache 未安装

sudo yum install httpd -y

如果你能告诉我 CentOS 具体版本(如 7.9 / 8 / Stream),我可以给你更精确的命令。

0