可以的,但需要注意 “Apache2” 这个说法在 CentOS 上的具体含义:
所以在 CentOS 上你通常不是安装 apache2,而是安装 httpd,但本质上它们都是 Apache HTTP Server。
以 CentOS 7 为例:
# 安装
sudo yum install httpd -y
# 启动
sudo systemctl start httpd
# 设置开机自启
sudo systemctl enable httpd
# 查看状态
sudo systemctl status httpd
如果是 CentOS 8 / Stream:
sudo dnf install httpd -y
sudo systemctl start httpd
所以你完全可以在 CentOS 上运行“Apache2(即 Apache 2.x)”。
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
/etc/httpd//etc/apache2/✅ 结论:CentOS 可以运行 Apache2,只是包名是 httpd,功能和 Ubuntu 的 apache2 基本一样。
如果你是想把 Ubuntu 的 apache2 配置迁移到 CentOS,我也可以帮你对比差异。