在 CentOS 上开启(启动)Apache,通常按以下步骤操作(以 CentOS 7/8 为例,Apache 包名是 httpd):
sudo yum install httpd -y
(CentOS 8 可用 dnf)
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
看到 active (running) 就说明启动成功。
如果开了 firewalld:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
如果是云服务器,还要在安全组里放行 80 端口。
浏览器访问服务器 IP:
http://服务器IP
看到 Apache 测试页即成功。
service httpd start
chkconfig httpd on
journalctl -xe
或看日志:
tail -n 50 /var/log/httpd/error_log
如果你用的是 CentOS 哪个版本、是不是最小化安装、有没有 SELinux 问题,可以告诉我,我帮你具体看。