CentOS 里 没有 Apache2 这个包名,它使用的是 Apache HTTP Server,官方包名是 httpd。下面我按 CentOS 版本给你说明正确安装方式。
cat /etc/centos-release
常见版本:
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
systemctl status httpd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
浏览器访问:
http://服务器IP
默认网页目录:
/var/www/html
sudo dnf install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
| 作用 | 路径 |
|---|---|
| 主配置文件 | /etc/httpd/conf/httpd.conf |
| 虚拟主机配置 | /etc/httpd/conf.d/ |
| 网站根目录 | /var/www/html |
| 日志目录 | /var/log/httpd/ |
apache2httpdhttpd -v
输出示例:
Server version: Apache/2.4.x
如果你需要:
可以直接告诉我你的 CentOS 版本和使用场景,我可以一步步帮你配置。