在 CentOS 上启动 Apache(httpd) 通常有以下几种方式,取决于你使用的 CentOS 版本(CentOS 6 用 service,CentOS 7+ 用 systemctl)。
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
sudo systemctl stop httpd
sudo systemctl restart httpd
sudo service httpd start
sudo chkconfig httpd on
如果启动后浏览器访问不了,通常是防火墙没放行 80 端口。
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
浏览器访问:
http://服务器IP
看到 Apache 测试页 即成功。
sudo netstat -tunlp | grep :80
sudo yum install httpd -y
如果你能告诉我 CentOS 具体版本(如 7.9 / 8 / Stream),我可以给你更精确的命令。