在 CentOS 上,Apache 的软件包名是 httpd,而不是 apache2(apache2 是 Debian/Ubuntu 的叫法)。
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
sudo systemctl restart httpd
sudo systemctl stop httpd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
浏览器访问服务器 IP:
http://服务器IP
看到 Apache 测试页即成功。
如果你是在 CentOS 上使用 Docker / 编译安装的 Apache,或者你确认系统里真的有 apache2 命令,也可以告诉我,我给你对应的启动方式。