在 CentOS 上,Apache 的软件包名通常是 httpd(不是 apache2,apache2 是 Debian/Ubuntu 的叫法)。下面是在 CentOS 上安装和启动 Apache 的标准步骤:
sudo yum update -y
CentOS 8 及以上可用
dnf代替yum
sudo yum install httpd -y
或(CentOS 8+):
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
查看运行状态:
sudo systemctl status httpd
如果开启了 firewalld:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
浏览器访问:
http://服务器IP
看到 Apache HTTP Server Test Page 即成功。
/etc/httpd/conf/httpd.conf/var/www/html/var/log/httpdCentOS 没有 apache2 包,只有 httpd。
如果你是从 Ubuntu 转过来,记住:
| 系统 | 服务名 |
|---|---|
| CentOS | httpd |
| Ubuntu | apache2 |
如果你告诉我 CentOS 版本(6/7/8/Stream),我可以给你更精确的命令。