如何安装 Apache 在 Fedora 23

Apache 是世界上最受欢迎的 Web 服务器,部分原因在于它的强大功能、易于管理和灵活性。 在本教程中,我们将安装 Apache 在尚未安装 Web 服务器或数据库服务器的服务器上。

飞行前检查

  • 这些说明用于安装 Apache 在单 Fedora 23 节点。
  • 我们将使用 Liquid Web Self Managed Fedora 23服务器,我们将以非root用户身份登录。 如果您需要更多信息,请访问我们的教程如何添加用户并授予 Root 权限 Fedora 23.

第 1 步:安装 Apache

首先,我们将清理我们的包数据:

sudo dnf clean all

这应该会产生类似于以下内容的输出:

[root@host ~]# sudo dnf clean all
Cleaning repos: fedora stable-arch updates stable-noarch stable-generic
Cleaning up Everything

作为最佳实践,我们现在也将更新我们的包:

sudo dnf -y update

安装 Apache 就像只运行一个命令一样简单:

sudo dnf -y install httpd

步骤#2:允许 Apache 通过防火墙

通过 firewalld 允许默认的 HTTP 和 HTTPS 端口,端口 80 和 443:

sudo firewall-cmd --permanent --add-port=80/tcp

sudo firewall-cmd --permanent --add-port=443/tcp

现在重新加载防火墙以使新设置生效:

sudo firewall-cmd --reload

您应该在每个命令之后看到“成功”消息。

步骤#3:配置 Apache 开机启动

首先,开始 Apache:

sudo systemctl start httpd

放 Apache 在启动时启动:

sudo systemctl enable httpd

该命令应产生类似于以下内容的输出:

[root@host ~]# sudo systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

检查状态 Apache:

sudo systemctl status httpd

停止 Apache:

sudo systemctl stop httpd