发布于 2026-01-06 0 阅读
0

如何在 Amazon Linux 上安装 Apache Web 服务器 2 DEV 的全球展示挑战赛,由 Mux 呈现:展示你的项目!

如何在 Amazon Linux 2 上安装 Apache Web 服务器

由 Mux 主办的 DEV 全球展示挑战赛:展示你的项目!

介绍

在本教程中,我们将学习如何在 Amazon Linux 2 上安装 Apache Web 服务器。我们还将学习如何配置 Apache Web 服务器来运行简单的 HTML 网页。

先决条件

要学习本教程,您需要:

  • 一个 Amazon Linux 2 EC2 实例。
  • 具有 sudo 权限的用户。

安装 Apache Web 服务器并运行简单的 HTML 网页

步骤 1:安装 Apache Web 服务器

开始之前,我们需要更新软件包列表并升级已安装的软件包:



sudo yum update -y


Enter fullscreen mode Exit fullscreen mode

现在,我们可以安装Apache Web服务器了:



sudo yum install httpd -y


Enter fullscreen mode Exit fullscreen mode

步骤 2:启动 Apache Web 服务器

现在,我们可以启动Apache Web服务器了:

  • 启动 Apache 服务器


sudo systemctl start httpd


Enter fullscreen mode Exit fullscreen mode
  • 配置 Apache 在系统启动时运行


sudo systemctl enable httpd


Enter fullscreen mode Exit fullscreen mode

步骤 3:配置防火墙

现在,我们需要配置防火墙以允许HTTP流量:



sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload


Enter fullscreen mode Exit fullscreen mode

步骤 4:创建一个简单的 HTML 网页

在测试 Apache Web 服务器之前,我们需要更改/var/www/html目录的权限:



sudo chmod 777 /var/www/html


Enter fullscreen mode Exit fullscreen mode

现在,我们可以创建一个简单的HTML网页:



sudo vi /var/www/html/index.html

Enter fullscreen mode Exit fullscreen mode


<!DOCTYPE html>
<html>
<head>
<title>Apache Web Server</title>
</head>
<body>
<h1>Apache Web Server</h1>
<p>This is a simple HTML web page.</p>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode




步骤 5:测试 Apache Web 服务器

现在,我们可以通过在 Web 浏览器中打开 Amazon Linux 2 EC2 实例的公共 IP 地址来测试 Apache Web 服务器:

Apache Web 服务器

结论

在本教程中,我们学习了如何在 Amazon Linux 2 上安装 Apache Web 服务器。我们还学习了如何配置 Apache Web 服务器来运行简单的 HTML 网页。

参考

文章来源:https://dev.to/mkabumattar/how-to-install-apache-web-server-on-amazon-linux-2-31l