在 CentOS 上让 Apache(httpd) 开机自启动,取决于你使用的 CentOS 版本(CentOS 6 及以前用 service/chkconfig,CentOS 7 及以后用 systemd)。
systemctl start httpd
systemctl enable httpd
systemctl is-enabled httpd
输出应为:
enabled
systemctl status httpd # 查看状态
systemctl restart httpd # 重启
systemctl stop httpd # 停止
service httpd start
chkconfig httpd on
chkconfig --list httpd
应看到:
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
yum install httpd -y
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
可临时测试:
setenforce 0
(生产环境建议正确配置 SELinux 策略)
如果你能提供 CentOS 具体版本号,我可以给你更精确的操作步骤。