在 CentOS 上启动 Apache(httpd) 的方法取决于你使用的 CentOS 版本(CentOS 7 及以上使用 systemd,CentOS 6 及更早使用 service)。下面分别说明。
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
sudo service httpd status
如果提示 httpd: command not found 或找不到服务,先检查是否安装:
rpm -qa | grep httpd
或者:
which httpd
sudo yum install httpd -y
(CentOS 8 / Stream 可用 dnf)
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo systemctl stop firewalld
浏览器访问服务器 IP:
http://服务器IP
看到 Apache Test Page 或默认页面即成功。
sudo netstat -tulnp | grep 80
sudo tail -f /var/log/httpd/error_log
如果你愿意,可以告诉我:
cat /etc/centos-release)我可以更精确地帮你排查问题。