如何在Rocky Linux 9上安装Magento

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

Magento 是一个流行的开源电子商务平台,提供广泛的特性和功能。Magento的主要功能之一是其灵活性和可扩展性。它被设计为高度可定制,允许开发人员创建独特和定制的在线商店。它还支持多种语言、货币和税率,使其适用于在不同地区运营的企业。如何在Rocky Linux 9上安装Magento

在 Rocky Linux 9 上安装 Magento

第 1 步。第一步是将系统更新到最新版本的软件包列表。为此,请运行以下命令:

<span class="pln">sudo dnf check</span><span class="pun">-</span><span class="pln">update
sudo dnf install dnf</span><span class="pun">-</span><span class="pln">utils epel</span><span class="pun">-</span><span class="pln">release</span>

第 2 步。安装阿帕奇。

默认情况下,Apache 在 Rocky Linux 9 基础存储库中可用。现在我们使用以下命令安装最新版本的 Apache:dnf

<span class="pln">sudo dnf install httpd httpd</span><span class="pun">-</span><span class="pln">tools</span>

您可以通过输入以下命令来启动服务并将其配置为在启动时运行:httpd

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

若要使页面向公众开放,必须使用以下命令编辑防火墙规则以允许 Web 服务器上的 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="pln">zone</span><span class="pun">=</span><span class="kwd">public</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="pln">zone</span><span class="pun">=</span><span class="kwd">public</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>

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

  • 如何在 Rocky Linux √ 上安装 Apache。

第 3 步。安装 PHP。

PHP 是一种流行的脚本语言,可为数百万个网站和应用程序的动态内容提供支持。现在我们运行以下命令来安装 PHP:

<span class="pln">sudo dnf epel</span><span class="pun">-</span><span class="pln">release
sudo dnf install https</span><span class="pun">:</span><span class="com">//rpms.remirepo.net/enterprise/remi-release-9.rpm</span><span class="pln">
sudo dnf </span><span class="pun">--</span><span class="pln">disablerepo</span><span class="pun">=</span><span class="str">"*"</span> <span class="pun">--</span><span class="pln">enablerepo</span><span class="pun">=</span><span class="str">"remi-safe"</span><span class="pln"> list available 
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>

启用 Remi PHP 8.1 模块后,您现在可以安装 PHP 8.1 和常用的 PHP 扩展,如下所示:

<span class="pln">dnf install php php</span><span class="pun">-</span><span class="pln">cli php</span><span class="pun">-</span><span class="pln">mysqlnd php</span><span class="pun">-</span><span class="pln">opcache php</span><span class="pun">-</span><span class="pln">xml php</span><span class="pun">-</span><span class="pln">gd php</span><span class="pun">-</span><span class="pln">soap php</span><span class="pun">-</span><span class="pln">pdo php</span><span class="pun">-</span><span class="pln">bcmath php</span><span class="pun">-</span><span class="pln">intl php</span><span class="pun">-</span><span class="pln">mbstring php</span><span class="pun">-</span><span class="pln">json php</span><span class="pun">-</span><span class="pln">iconv php</span><span class="pun">-</span><span class="pln">zip unzip</span>

检查并验证已安装的版本:

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

接下来,编辑文件并更改一些值:php.ini

<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">php</span><span class="pun">.</span><span class="pln">ini</span>

更改以下值:

<span class="pln">memory_limit </span><span class="pun">=</span> <span class="lit">1024M</span><span class="pln">
upload_max_filesize </span><span class="pun">=</span> <span class="lit">256M</span><span class="pln">
zlib</span><span class="pun">.</span><span class="pln">output_compression </span><span class="pun">=</span><span class="pln"> on
max_execution_time </span><span class="pun">=</span> <span class="lit">18000</span><span class="pln">
date</span><span class="pun">.</span><span class="pln">timezone </span><span class="pun">=</span> <span class="typ">Asia</span><span class="pun">/</span><span class="typ">Jakarta</span>

保存并关闭文件,然后您需要使用以下命令安装所需的依赖项 PHP 钠扩展:

<span class="pln">sudo dnf install libsodium php</span><span class="pun">-</span><span class="pln">pear php</span><span class="pun">-</span><span class="pln">devel libsodium</span><span class="pun">-</span><span class="pln">devel make</span>

最后,使用以下命令安装 PHP 钠扩展:

<span class="pln">pecl channel</span><span class="pun">-</span><span class="pln">update pecl</span><span class="pun">.</span><span class="pln">php</span><span class="pun">.</span><span class="pln">net
pecl install libsodium</span>

返回文件。php.ini

<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">php</span><span class="pun">.</span><span class="pln">ini</span>

添加以下行:

<span class="pln">extension</span><span class="pun">=</span><span class="pln">sodium</span><span class="pun">.</span><span class="pln">so</span>

要验证是否安装了 PHP 钠,请运行以下命令:

<span class="pln">php </span><span class="pun">-</span><span class="pln">i </span><span class="pun">|</span><span class="pln"> grep sodium</span>

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

  • 如何在 Rocky Linux √ 上安装 PHP

第 4 步。安装 MariaDB。

默认情况下,MariaDB 在 Rocky Linux 9 基础存储库中可用。只需使用以下命令安装 MariaDB 软件包:dnf

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

安装完成后,启动数据库服务器的服务,然后启用相同的服务,以便它可以在系统重新启动时自动启动:

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

默认情况下,MariaDB 未强化。您可以使用脚本保护 MariaDB。您应该仔细阅读并在每个步骤下方仔细阅读,这将设置root密码,删除匿名用户,禁止远程root登录,并删除测试数据库和对安全MariaDB的访问权限:mysql_secure_installation

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

首先,使用以下命令登录到 MariaDB shell:

<span class="pln">mysql</span>

现在我们使用以下命令为 Magento 创建一个数据库和用户:

<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE magento</span><span class="pun">;</span>
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE USER </span><span class="str">'magento'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'your-strong-password'</span><span class="pun">;</span>
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> GRANT ALL ON magento</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'magento'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'your-strong-password'</span><span class="pln"> WITH GRANT OPTION</span><span class="pun">;</span>
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> flush privileges</span><span class="pun">;</span>
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span> <span class="kwd">exit</span><span class="pun">;</span>

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

  • 如何在 Rocky Linux √ 上安装 MariaDB

第5步。正在安装作曲家。

默认情况下,Composer 在 Rocky Linux 9 基础存储库中不可用。现在运行以下命令,使用以下命令从其官方网站下载 Composer 安装程序文件:wget

<span class="pln">wget https</span><span class="pun">:</span><span class="com">//getcomposer.org/installer -O composer-installer.php</span>

接下来,使用以下命令运行下载的作曲家安装文件:

<span class="pln">php composer</span><span class="pun">-</span><span class="pln">installer</span><span class="pun">.</span><span class="pln">php </span><span class="pun">--</span><span class="pln">filename</span><span class="pun">=</span><span class="pln">composer </span><span class="pun">--</span><span class="pln">install</span><span class="pun">-</span><span class="pln">dir</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span>

通过运行以下命令验证编辑器安装:

<span class="pln">composer </span><span class="pun">--</span><span class="pln">version</span>

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

  • 如何在 Rocky Linux √ 上安装 Composer

第 6 步。在 Rocky Linux 9 上下载 Magento。

现在运行以下命令,从GitHub页面下载最新版本的Magento:

<span class="pln">wget https</span><span class="pun">:</span><span class="com">//github.com/magento/magento2/archive/refs/tags/2.4.4-p2.zip</span>

接下来,使用以下命令解压缩下载的文件:

<span class="pln">unzip </span><span class="lit">2.4</span><span class="pun">.</span><span class="lit">4</span><span class="pun">-</span><span class="pln">p2</span><span class="pun">.</span><span class="pln">zip
mv magento2</span><span class="pun">-*</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">magento2</span>

将目录更改为Magento并安装所有必需的PHP依赖项:

<span class="pln">cd </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">magento2
composer install</span>

我们需要更改一些文件夹权限:

<span class="pln">chown </span><span class="pun">-</span><span class="pln">R apache</span><span class="pun">:</span><span class="pln">apache </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">magento2</span>

接下来,使用以下命令设置所需的权限:

<span class="pln">cd </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">magento2
find </span><span class="kwd">var</span><span class="pln"> generated vendor pub</span><span class="pun">/</span><span class="kwd">static</span><span class="pln"> pub</span><span class="pun">/</span><span class="pln">media app</span><span class="pun">/</span><span class="pln">etc </span><span class="pun">-</span><span class="pln">type f </span><span class="pun">-</span><span class="kwd">exec</span><span class="pln"> chmod g</span><span class="pun">+</span><span class="pln">w </span><span class="pun">{}</span> <span class="pun">+</span><span class="pln">
find </span><span class="kwd">var</span><span class="pln"> generated vendor pub</span><span class="pun">/</span><span class="kwd">static</span><span class="pln"> pub</span><span class="pun">/</span><span class="pln">media app</span><span class="pun">/</span><span class="pln">etc </span><span class="pun">-</span><span class="pln">type d </span><span class="pun">-</span><span class="kwd">exec</span><span class="pln"> chmod g</span><span class="pun">+</span><span class="pln">ws </span><span class="pun">{}</span> <span class="pun">+</span><span class="pln">
chown </span><span class="pun">-</span><span class="pln">R apache</span><span class="pun">:</span><span class="pln">apache </span><span class="pun">.</span><span class="pln"> 
chmod u</span><span class="pun">+</span><span class="pln">x bin</span><span class="pun">/</span><span class="pln">magento</span>

步骤 7.配置阿帕奇。

现在我们使用以下命令配置 Magento VirtualHost 文件:

<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">httpd</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">magento</span><span class="pun">.</span><span class="pln">conf</span>

添加以下文件:

<span class="tag"><VirtualHost</span><span class="pln"> *:80</span><span class="tag">></span><span class="pln">
   ServerAdmin admin@your-domain.com
   ServerName magento.your-domain.com
   DocumentRoot /var/www/html/magento2/
   DirectoryIndex index.php

 </span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">html</span><span class="pun">/</span><span class="atn">magento2</span><span class="tag">/></span><span class="pln">
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   Order allow,deny
   allow from all
 </span><span class="tag"></Directory></span><span class="pln">

   ErrorLog /var/log/httpd/magento_error.log
   CustomLog /var/log/httpd/magento_access.log combined
</span><span class="tag"></VirtualHost></span>

保存并关闭文件,然后重新启动 Apache 服务以应用更改:

<span class="pln">sudo systemctl restart httpd</span>

第8步。在 Rocky Linux 9 上安装 Magento。

从Magento版本2.2开始,通过Web界面安装Magento的选项已被删除。相反,您需要通过命令行执行安装。首先,导航到 magento2 目录并使用以下命令禁用 Elasticsearch 模块:

<span class="pln">cd </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">magento2</span><span class="pun">/</span><span class="pln">
sudo </span><span class="pun">-</span><span class="pln">u apache bin</span><span class="pun">/</span><span class="pln">magento </span><span class="kwd">module</span><span class="pun">:</span><span class="pln">disable </span><span class="pun">{</span><span class="typ">Magento_Elasticsearch</span><span class="pun">,</span><span class="typ">Magento_Elasticsearch6</span><span class="pun">,</span><span class="typ">Magento_Elasticsearch7</span><span class="pun">}</span>

接下来,使用以下命令安装Magento

<span class="pln">sudo </span><span class="pun">-</span><span class="pln">u apache bin</span><span class="pun">/</span><span class="pln">magento setup</span><span class="pun">:</span><span class="pln">install </span><span class="pun">--</span><span class="pln">admin</span><span class="pun">-</span><span class="pln">firstname</span><span class="pun">=</span><span class="str">"meilana"</span> <span class="pun">--</span><span class="pln">admin</span><span class="pun">-</span><span class="pln">lastname</span><span class="pun">=</span><span class="str">"maria"</span> <span class="pun">--</span><span class="pln">admin</span><span class="pun">-</span><span class="pln">email</span><span class="pun">=</span><span class="str">"admin@your-domain.com"</span> <span class="pun">--</span><span class="pln">admin</span><span class="pun">-</span><span class="pln">user</span><span class="pun">=</span><span class="str">"admin"</span> <span class="pun">--</span><span class="pln">admin</span><span class="pun">-</span><span class="pln">password</span><span class="pun">=</span><span class="str">"your-strong-passwd"</span> <span class="pun">--</span><span class="pln">db</span><span class="pun">-</span><span class="pln">name</span><span class="pun">=</span><span class="str">"magento"</span> <span class="pun">--</span><span class="pln">db</span><span class="pun">-</span><span class="pln">host</span><span class="pun">=</span><span class="str">"localhost"</span> <span class="pun">--</span><span class="pln">db</span><span class="pun">-</span><span class="pln">user</span><span class="pun">=</span><span class="str">"magento"</span> <span class="pun">--</span><span class="pln">db</span><span class="pun">-</span><span class="pln">password</span><span class="pun">=</span><span class="str">"your-strong-password"</span> <span class="pun">--</span><span class="pln">language</span><span class="pun">=</span><span class="pln">en_US </span><span class="pun">--</span><span class="pln">currency</span><span class="pun">=</span><span class="pln">USD </span><span class="pun">--</span><span class="pln">timezone</span><span class="pun">=</span><span class="typ">Asia</span><span class="pun">/</span><span class="typ">Jakarta</span> <span class="pun">--</span><span class="pln">cleanup</span><span class="pun">-</span><span class="pln">database </span><span class="pun">--</span><span class="kwd">base</span><span class="pun">-</span><span class="pln">url</span><span class="pun">=</span><span class="pln">http</span><span class="pun">:</span><span class="com">//"magento.your-domain.com"</span>

之后,现在设置 Magento cron 作业:

<span class="pln">cd </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">magento2
sudo </span><span class="pun">-</span><span class="pln">u apache bin</span><span class="pun">/</span><span class="pln">magento cron</span><span class="pun">:</span><span class="pln">install</span>

第9步。访问Magento Web界面。

成功安装后,打开您的网络浏览器并使用 URL .您将被重定向到以下页面:http://magento.your-domain.com

如何在Rocky Linux 9上安装Magento

感谢您使用本教程在您的Rocky Linux 9系统上安装Magento电子商务平台。有关其他帮助或有用信息,我们建议您查看Magento官方网站


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

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

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