centos

如何在 CentOS 上启用 Apache2

小樊
49
2025-09-11 19:56:33
栏目: 智能运维

在 CentOS 上启用 Apache2(通常称为 httpd)的步骤如下:

  1. 首先,确保您已经安装了 Apache。如果尚未安装,请运行以下命令来安装它:
sudo yum install httpd
  1. 安装完成后,启动 Apache 服务:
sudo systemctl start httpd
  1. 要使 Apache 在系统启动时自动运行,请执行以下命令:
sudo systemctl enable httpd
  1. 确认 Apache 服务正在运行:
sudo systemctl status httpd

如果服务正在运行,您将看到类似于以下的输出:

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since ...
  1. 现在,您可以通过访问服务器的 IP 地址或域名来访问 Apache。在浏览器中输入以下内容:
http://your_server_ip_or_domain

您应该看到 Apache 的默认页面。

  1. 如果需要配置防火墙以允许 HTTP 和 HTTPS 流量,请运行以下命令:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

现在,您已经在 CentOS 上启用了 Apache2。如有需要,请根据您的需求进行配置。

0
看了该问题的人还看了