如何在 Fedora 37 上安装 LEMP

Linux命令 Edge插件网 2年前 (2023-03-29) 462次浏览 已收录 0个评论

LEMP 是终极强大的软件堆栈,可为 Web 开发和部署提供可靠、安全和闪电般的环境。对于希望将 Web 应用程序提升到新水平的开发人员来说,这是首选,我们在这里帮助您入门。

如何在 Fedora 37 上安装 LEMP

在 Fedora 37 上安装 LEMP

第 1 步。在继续之前,请更新您的 Fedora 操作系统以确保所有现有软件包都是最新的。使用此命令更新服务器软件包:

<span class="pln">sudo dnf upgrade
sudo dnf update</span>

第 2 步。安装Nginx。

默认情况下,Nginx 软件包位于默认的 Fedora 37 存储库中。现在运行以下命令将 Nginx 安装到您的 Fedora 系统中:

<span class="pln">sudo dnf install nginx</span>

安装完成后,通过运行以下命令启动 Nginx 服务并使其在启动时自动启动:

<span class="pln">sudo systemctl start nginx
sudo systemctl enable nginx</span>

我们需要启用防火墙才能过滤进入我们服务器的流量。现在我们使用以下命令在防火墙中添加 HTTP 和 HTTPS 端口:

<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">http
sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">https
sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">reload</span>

要验证 Nginx 的安装,您可以通过打开 Web 浏览器并导航到 来访问默认欢迎页面。您将看到以下屏幕:http://localhost or http://your-IP-address

如何在 Fedora 37 上安装 LEMP

有关安装 Nginx 的其他资源,请阅读下面的帖子:

  • 如何在Fedora Linux √上安装 Nginx

第 3 步。安装 MariaDB。

默认情况下,MariaDB 在 Fedora 37 的默认存储库中可用,因此您可以使用包管理器安装它。要安装 MariaDB,请运行以下命令:dnf

<span class="pln">sudo dnf install mariadb</span><span class="pun">-</span><span class="pln">server mariadb</span><span class="pun">-</span><span class="pln">client</span>

安装完成后,使用以下命令启动并启用 MariaDB 以在引导时运行:

<span class="pln">sudo systemctl start mariadb
sudo systemctl enable mariadb</span>

建议保护 MariaDB 安装,以防止未经授权访问数据库。运行以下命令以运行安全脚本:

<span class="pln">sudo mysql_secure_installation</span>

系统将提示您回答有关 MariaDB 安全设置的一些问题。按照提示操作并回答问题:

<span class="typ">Remove</span><span class="pln"> anonymous users</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> Y
</span><span class="typ">Disallow</span><span class="pln"> root login remotely</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> Y
</span><span class="typ">Remove</span><span class="pln"> test database </span><span class="kwd">and</span><span class="pln"> access to it</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> Y</span>

您可以使用以下命令连接到 MariaDB 服务器来验证 MariaDB 在 Fedora 37 上的安装:

<span class="pln">sudo mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>

输入您在安全安装过程中设置的 root 密码。如果连接成功,您将看到 MariaDB shell 提示符,如下所示:

<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span>

有关安装 MariaDB 的其他资源,请阅读以下帖子:

  • 如何在 Fedora Linux √ 上安装 MariaDB

第 4 步。安装 PHP。

要在 Fedora 上安装 PHP,您需要设置 REMI 存储库。现在使用以下命令导入 Remi PHP 存储库:

<span class="pln">sudo dnf install http</span><span class="pun">:</span><span class="com">//rpms.remirepo.net/fedora/remi-release-37.rpm</span>

现在,验证安装:

<span class="pln">dnf repolist </span><span class="pun">|</span><span class="pln"> grep remi</span>

输出:

<span class="pun">[</span><span class="pln">root@idroot</span><span class="pun">.</span><span class="pln">us </span><span class="pun">~]</span><span class="pln">$ dnf repolist </span><span class="pun">|</span><span class="pln"> grep remi
remi </span><span class="typ">Remi</span><span class="str">'s RPM repository - <a href="https://www.edge66.com/edgetag/fedora-37" title="查看更多关于Fedora 37的文章" target="_blank">Fedora 37</a> - x86_64
remi-modular Remi'</span><span class="pln">s </span><span class="typ">Modular</span><span class="pln"> repository </span><span class="pun">-</span> <span class="typ">Fedora</span> <span class="lit">37</span> <span class="pun">-</span><span class="pln"> x86_64</span>

默认情况下,PHP 软件包位于 Fedora 37 的默认存储库中。现在运行以下命令将 PHP 8.1 软件包安装到您的 Fedora 系统中:

<span class="pln">sudo dnf </span><span class="kwd">module</span><span class="pln"> enable php</span><span class="pun">:</span><span class="pln">remi</span><span class="pun">-</span><span class="lit">8.1</span><span class="pln">
sudo dnf install php php</span><span class="pun">-</span><span class="pln">common php</span><span class="pun">-</span><span class="pln">cli</span>

此外,如果要安装 PHP 8.1 最常用的扩展,请使用以下命令:

<span class="pln">sudo dnf install php</span><span class="pun">-</span><span class="pln">cli php</span><span class="pun">-</span><span class="pln">fpm php</span><span class="pun">-</span><span class="pln">curl php</span><span class="pun">-</span><span class="pln">mysqlnd php</span><span class="pun">-</span><span class="pln">gd php</span><span class="pun">-</span><span class="pln">opcache php</span><span class="pun">-</span><span class="pln">zip php</span><span class="pun">-</span><span class="pln">intl php</span><span class="pun">-</span><span class="pln">common php</span><span class="pun">-</span><span class="pln">bcmath php</span><span class="pun">-</span><span class="pln">imagick php</span><span class="pun">-</span><span class="pln">xmlrpc php</span><span class="pun">-</span><span class="pln">json php</span><span class="pun">-</span><span class="pln">readline php</span><span class="pun">-</span><span class="pln">memcached php</span><span class="pun">-</span><span class="pln">redis php</span><span class="pun">-</span><span class="pln">mbstring php</span><span class="pun">-</span><span class="pln">apcu php</span><span class="pun">-</span><span class="pln">xml php</span><span class="pun">-</span><span class="pln">dom php</span><span class="pun">-</span><span class="pln">redis php</span><span class="pun">-</span><span class="pln">memcached php</span><span class="pun">-</span><span class="pln">memcache</span>

安装 PHP 后,使用以下命令检查其版本:

<span class="pln">php </span><span class="pun">-</span><span class="pln">v</span>

输出:

<span class="pln">PHP </span><span class="lit">8.1</span><span class="pun">.</span><span class="lit">13</span> <span class="pun">(</span><span class="pln">cli</span><span class="pun">)</span> <span class="pun">(</span><span class="pln">built</span><span class="pun">:</span> <span class="typ">Nov</span> <span class="lit">28</span> <span class="lit">2022</span> <span class="lit">11</span><span class="pun">:</span><span class="lit">36</span><span class="pun">:</span><span class="lit">13</span><span class="pun">)</span> <span class="pun">(</span><span class="pln">NTS gcc x86_64</span><span class="pun">)</span>
<span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">)</span> <span class="typ">The</span><span class="pln"> PHP </span><span class="typ">Group</span>
<span class="typ">Zend</span> <span class="typ">Engine</span><span class="pln"> v4</span><span class="pun">.</span><span class="lit">1.13</span><span class="pun">,</span> <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">)</span> <span class="typ">Zend</span> <span class="typ">Technologies</span>
    <span class="kwd">with</span> <span class="typ">Zend</span> <span class="typ">OPcache</span><span class="pln"> v8</span><span class="pun">.</span><span class="lit">1.13</span><span class="pun">,</span> <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">),</span> <span class="kwd">by</span> <span class="typ">Zend</span> <span class="typ">Technologies</span>

有关安装 PHP 的其他资源,请阅读下面的帖子:

  • 如何在 Fedora Linux √ 上安装 PHP

第5步。测试您的 LEMP 堆栈。

完成 Nginx、MySQL 和 PHP 的安装和配置后,您可以通过使用一些简单的代码创建一个 PHP 文件来测试 LEMP 堆栈。以下是执行此操作的步骤:

在 Nginx 文档根目录中创建一个名为“info.php”的新文件:

<span class="pln">nano </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">info</span><span class="pun">.</span><span class="pln">php</span>

将以下代码添加到文件中:

<span class="pun"><?</span><span class="pln">php
phpinfo</span><span class="pun">();</span>
<span class="pun">?></span>

保存文件并退出编辑器并打开 Web 浏览器,导航到 。您应该会看到一个页面,其中包含有关 PHP 安装的信息。http://your-IP-address/info.php

感谢您使用本教程在您的 Fedora 37 系统上安装 LEMP 。有关其他帮助或有用信息,我们建议您查看 LEMP 官方网站。


Edge插件网 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何在 Fedora 37 上安装 LEMP
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址