Moodle是一个免费的开源学习管理系统(LMS),世界各地的教育工作者和机构使用它来创建在线学习环境。它旨在灵活且可定制,为课程创建、协作、评估和移动支持提供一系列工具。
在 Rocky Linux 9 上安装 Moodle
第 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</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 </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">sudo dnf install php 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">gd php</span><span class="pun">-</span><span class="pln">curl php</span><span class="pun">-</span><span class="pln">zip php</span><span class="pun">-</span><span class="pln">mbstring php</span><span class="pun">-</span><span class="pln">opcache php</span><span class="pun">-</span><span class="pln">intl php</span><span class="pun">-</span><span class="pln">mysqlnd</span>
检查并验证已安装的版本:
<span class="pln">php </span><span class="pun">-</span><span class="pln">v</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>
现在我们使用以下命令为 Moodle 创建一个数据库和用户:
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE moodledb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci</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">'moodleuser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'Your-Str0ng-Passwd'</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 SELECT</span><span class="pun">,</span><span class="pln">INSERT</span><span class="pun">,</span><span class="pln">UPDATE</span><span class="pun">,</span><span class="pln">DELETE</span><span class="pun">,</span><span class="pln">CREATE</span><span class="pun">,</span><span class="pln">CREATE TEMPORARY TABLES</span><span class="pun">,</span><span class="pln">DROP</span><span class="pun">,</span><span class="pln">INDEX</span><span class="pun">,</span><span class="pln">ALTER ON moodledb</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'moodleuser'</span><span class="pun">@</span><span class="str">'localhost'</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步。在 Rocky Linux 9 上安装 Moodle。
现在运行以下命令,从官方页面下载最新版本的 Moodle:
<span class="pln">wget </span><span class="pun">-</span><span class="pln">c https</span><span class="pun">:</span><span class="com">//download.moodle.org/download.php/stable401/moodle-latest-401.tgz</span>
接下来,解压缩下载的文件:
<span class="pln">tar </span><span class="pun">-</span><span class="pln">xzvf moodle</span><span class="pun">-</span><span class="pln">latest</span><span class="pun">-</span><span class="lit">401.tgz</span><span class="pln"> mv moodle </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">chmod </span><span class="lit">770</span> <span class="pun">-</span><span class="pln">R </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">moodledata chown apache</span><span class="pun">:</span><span class="pln">apache </span><span class="pun">-</span><span class="pln">R </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">moodledata</span>
第 6 步。配置心情。
首先,切换到之前提取的 Moodle 文件夹。例如:
<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">moodle</span><span class="pun">/</span><span class="pln"> cp config</span><span class="pun">-</span><span class="pln">dist</span><span class="pun">.</span><span class="pln">php config</span><span class="pun">.</span><span class="pln">php nano config</span><span class="pun">.</span><span class="pln">php</span>
设置正确的数据库类型、正确的数据库主机、数据库名称、数据库用户和用户密码:
<span class="pln">$CFG</span><span class="pun">-></span><span class="pln">dbtype </span><span class="pun">=</span> <span class="str">'mariadb'</span><span class="pun">;</span> <span class="com">// 'pgsql', 'mariadb', 'mysqli', 'auroramysql', 'sqlsrv' or 'oci'</span><span class="pln"> $CFG</span><span class="pun">-></span><span class="pln">dblibrary </span><span class="pun">=</span> <span class="str">'native'</span><span class="pun">;</span> <span class="com">// 'native' only at the moment</span><span class="pln"> $CFG</span><span class="pun">-></span><span class="pln">dbhost </span><span class="pun">=</span> <span class="str">'localhost'</span><span class="pun">;</span> <span class="com">// eg 'localhost' or 'db.isp.com' or IP</span><span class="pln"> $CFG</span><span class="pun">-></span><span class="pln">dbname </span><span class="pun">=</span> <span class="str">'moodledb'</span><span class="pun">;</span> <span class="com">// database name, eg moodle</span><span class="pln"> $CFG</span><span class="pun">-></span><span class="pln">dbuser </span><span class="pun">=</span> <span class="str">'moodleuser'</span><span class="pun">;</span> <span class="com">// your database username</span><span class="pln"> $CFG</span><span class="pun">-></span><span class="pln">dbpass </span><span class="pun">=</span> <span class="str">'Your-Str0ng-Passwd'</span><span class="pun">;</span> <span class="com">// your database password</span><span class="pln"> $CFG</span><span class="pun">-></span><span class="pln">prefix </span><span class="pun">=</span> <span class="str">'mdl_'</span><span class="pun">;</span> <span class="com">// prefix to use for all table names</span>
此外,设置用于访问您的 Moodle 网站的 URL:
<span class="pln">$CFG</span><span class="pun">-></span><span class="pln">wwwroot </span><span class="pun">=</span> <span class="str">'http://learning.your-domain.com'</span><span class="pun">;</span><span class="pln"> $CFG</span><span class="pun">-></span><span class="pln">dataroot </span><span class="pun">=</span> <span class="str">'/var/www/html/moodledata'</span><span class="pun">;</span>
第 6 步。为 Moodle 配置 Apache。
现在我们使用以下命令配置 Moodle 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">moodle</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"> ServerName learning.your-domain.com ServerAlias www.learning.your-domain.com ServerAdmin admin@your-domain.com DocumentRoot /var/www/html/moodle/ </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">moodle</span><span class="tag">></span><span class="pln"> Options Indexes FollowSymLinks AllowOverride All Require all granted RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] </span><span class="tag"></Directory></span> <span class="tag"></VirtualHost></span>
保存并关闭文件,然后重新启动 Apache 服务以应用更改:
<span class="pln">sudo systemctl restart httpd</span>
步骤 7.访问 Moodle Web 界面。
成功安装后,打开您的网络浏览器并使用 URL 访问 Moodle。您将被重定向到以下页面:http://learning.your-domain.com
感谢您使用本教程在您的 Rocky Linux 9 系统上安装 Moodle 学习平台或课程管理系统 (CMS)。如需其他帮助或有用信息,我们建议您查看 Moodle 官方网站。