在Debian 9上安装Moodle eLearning Platform

在Debian 9上安装Moodle eLearning Platform

Moodle是一个灵活而强大的免费开源课程管理系统和用PHP编写的电子学习平台,通常部署在Linux下的Apache / Nginx Web服务器上,具有PHP和MySQL / MariaDB数据库管理系统,也称为LAMP或LEMP。

本教程将介绍如何在Debian 9发行版中安装和配置最新版本的Moodle,以便在您的场所创建一个电子学习平台。

Moodle平台提供直观的网络界面,教育工作者和培训师可以使用它来存储课程数据并跟踪学生,成绩和在线课程。 全球大多数主要大学都在部署Moodle电子学习平台,以便为学生和教师提供便利的教育活动。

要求

为了成功安装和部署Moodle,您的服务器需要满足以下要求。

  • Debian 9服务器在裸机服务器计算机或虚拟专用服务器上安装时具有最低软件要求
  • 通过控制台或SSH直接访问root帐户,或通过sudo实用程序远程或直接访问具有root权限的帐户
  • 配置有静态IP地址的网络接口卡
  • 要使用Moodle电子邮件注册,通知或其他类型的功能,您应该在您的场所正确设置邮件服务器,并且可以访问IMAP,POP3和SMTP服务。
  • 私有或公共域名,具体取决于您的部署,具有为Web服务配置的正确DNS记录。 如果没有有效或注册的域名,您可以执行安装并通过服务器IP地址访问网站

安装Apache,PHP和MySQL

在第一步中,在开始安装和配置Moodle平台之前,首先使用root帐户或具有root权限的帐户登录到您的服务器,然后通过发出以下命令开始更新Debian系统存储库和软件包。

apt update
apt upgrade

接下来,在更新系统软件后,通过执行以下命令配置Debian服务器的名称。 确保替换hostname变量以匹配您自己的设置,如下面的示例所示。

hostnamectl set-hostname www.myblog.com

然后,您可以通过发出以下命令来验证计算机主机名和主机文件。

hostnamectl
cat /etc/hostname
hostname –s
hostname –f

要应用内核更新并应用主机名更改,请发出以下命令以重新启动计算机。

systemctl reboot

用于部署Moodle学习平台的最重要的LAMP组件之一是RDBMS数据库,Web应用程序使用该数据库来存储不同的配置,例如用户,会话,联系人和其他数据。 在本教程中,我们将使用MariaDB数据库后端配置Moodle CMS,并对MySQL数据库进行环回访问。 这意味着只能通过localhost或127.0.0.1地址访问数据库。 无法与MySQL数据库建立外部连接。 要在Debian 9服务器中安装MariaDB数据库服务器和客户端,请发出以下命令。

apt install mariadb-server mariadb-client

在MariaDB数据库完成在Debian服务器上安装之后,发出netstat命令,如下例所示,以检查服务是否已启动并正在运行并监听localhost端口3306上的连接。

netstat –tlpn | grep mysql

如果默认情况下在Debian系统中未安装netstat网络实用程序,请执行以下命令进行安装。

apt install net-tools

在安装时,Debian 9中没有正确保护MySQL root帐户。 您可以在没有root密码的情况下登录数据库。 为了保护root帐户,请登录MySQL服务器控制台并安全执行以下命令。

mysql -h localhost
Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1


Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed
MariaDB [mysql]> update user set plugin='' where user='root';
Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> exit
Bye

在正确实施数据库root帐户后,在安装数据库时执行Debian拉伸存储库提供的mysql_secure_installation脚本,以进一步保护MySQL数据库。脚本将询问您一系列旨在保护MariaDB数据库的问题:您想要更改MySQL root密码,删除匿名用户,禁用远程root登录和删除测试数据库。 通过发出以下命令来执行脚本,并确保为所有问题键入yes ,如下面的脚本输出摘录所示:

mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!


In order to log into MariaDB to secure it, we'll need the current

password for the root user. If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.


Enter current password for root (enter for none):

OK, successfully used password, moving on...


Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.


You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them. This is intended only for testing, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.


Remove anonymous users? [Y/n] y

... Success!


Normally, root should only be allowed to connect from 'localhost'. This

ensures that someone cannot guess at the root password from the network.


Disallow root login remotely? [Y/n] y

... Success!


By default, MariaDB comes with a database named 'test' that anyone can

access. This is also intended only for testing, and should be removed

before moving into a production environment.


Remove test database and access to it? [Y/n] y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!


Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.


Reload privilege tables now? [Y/n] y

... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

最后,在您保护MySQL守护程序之后,登录到数据库控制台并且不为root帐户提供密码。 如果没有为root帐户提供密码,则应拒绝访问数据库,如以下命令摘录所示:

mysql -h localhost -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

如果提供root密码,则应授予登录MySQL数据库控制台的权限 ,如命令示例所示:

mysql -h localhost -u root -p
Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 15

Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit

Bye

Moodle CMS是一个基于Web的应用程序,主要使用PHP服务器端编程语言编写。 到目前为止,我们只安装了LAMP的MySQL数据库组件。 为了执行应用程序的PHP文件脚本,必须在系统中安装Web服务器,例如Apache HTTP服务器和PHP处理网关。 为了安装Apache Web服务器和PHP解释器以及应用程序正常运行所需的所有必需PHP模块,请在服务器控制台中发出以下命令。

apt install apache2 libapache2-mod-php7.0 php7.0 php7.0-mysql php7.0-gd php7.0-opcache php7.0-json php7.0-mbstring php7.0-xml php7.0-ldap php7.0-cli php7.0-curl php7.0-ldap php7.0-zip php7.0-bcmath php-imagick php7.0-xmlrpc php7.0-soap php7.0-intl

发出以下命令以验证系统中是否已启用所有已安装的PHP模块

php7.0 –m

安装Apache和PHP后,通过发出以root权限的命令,测试Web服务器是否已启动并正在运行并在端口80上监听网络连接。

netstat –tlpn

从netstat命令输出中我们可以看到Apache Web服务器正在监听端口80上的传入网络连接。对于相同的任务,您还可以使用ss命令,默认情况下,该命令在Debian 9中自动安装。

ss- tulpn

如果在Debian服务器中安装并启用了UFW防火墙应用程序,则应添加新规则以允许HTTP流量通过发出以下命令来通过防火墙。

ufw allow WWW

要么

ufw allow 80/tcp

如果系统管理员使用iptables原始规则来管理Debian服务器中的防火墙规则,请添加以下规则以允许防火墙上的端口80入站流量,以便访问者可以浏览在线应用程序。

apt-get install -y iptables-persistent
iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT
netfilter-persistent save
systemctl restart netfilter-persistent
systemctl status netfilter-persistent
systemctl enable netfilter-persistent.service

如果您通过SSH远程管理Debian服务器,请确保添加以下规则以允许传入SSH连接到您的计算机。

iptables -I INPUT -p tcp --destination-port 22 -j ACCEPT
netfilter-persistent save
systemctl restart netfilter-persistent

您可能还需要通过发出以下命令来启用并激活Moodle应用程序所需的以下Apache模块才能正常运行。

a2enmod rewrite
systemctl restart apache2

最后,通过HTTP协议访问Debian计算机IP地址或域名或服务器FQDN,测试Apache Web服务器默认网页是否可以显示在客户端浏览器中,如下图所示。 如果您不知道您的机器IP地址,请执行ifconfigip命令以显示您的服务器的IP地址。

HTTP://your_domain.tld

在下一步编辑PHP默认配置文件,以确保启用以下PHP变量并正确配置PHP 时区设置并匹配您的系统地理位置。 打开/etc/php/7.0/apache2/php.ini文件进行编辑,并确保以下行设置如下。 此外,最初,备份PHP配置文件。

cp /etc/php/7.0/apache2/php.ini{,.backup}
nano /etc/php/7.0/apache2/php.ini

php.ini配置文件中搜索,编辑和更改以下变量:

file_uploads = On
memory_limit = 128M
post_max_size = 80M
upload_max_filesize = 80M
default_charset = UTF-8
date.timezone = Europe/London

如果是这种情况,请将upload_max_file_size变量增加为适合支持大文件附件,并通过查看PHP文档提供的时区列表,在以下链接中将date.timezone变量替换为您的地理时间http://php.net/manual /en/timezones.php

如果您想通过适用于PHP7的OPCache插件来提高网站页面的加载速度,请在[opcache]语句下面的PHP解释器配置文件的底部附加以下OPCache设置,详情如下:

nano /etc/php/7.0/apache2/conf.d/10-opcache.ini
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

关闭php.ini配置文件并检查验证PHP配置文件的结束是否通过发出以下命令检查是否已正确添加OPCache变量。

grep opcache /etc/php/7.0/apache2/conf.d/10-opcache.ini

完成上述所有更改后,重新启动Apache守护程序以通过发出以下命令来应用新更改。

systemctl restart apache2

要通过HTTPS协议访问Moodle Web界面以保护客户端的流量,请发出以下命令以启用Apache Web服务器SSL模块和SSL站点配置文件。

a2enmod ssl
a2ensite default-ssl.conf

接下来,使用文本编辑器打开Apache默认SSL站点配置文件,并通过在DocumentRoot指令之后添加以下代码行来启用URL重写规则,如下面的示例所示:

nano /etc/apache2/sites-enabled/default-ssl.conf

SSL站点配置文件摘录:

<Directory /var/www/html>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>

此外,对VirtualHost行进行以下更改,如下面的摘录所示:

<VirtualHost *:443>

关闭SSL Apache文件并打开/etc/apache2/sites-enabled/000-default.conf文件进行编辑,并添加与SSL配置文件相同的URL重写规则。 在DocumentRoot语句之后插入代码行,如下例所示。

<Directory /var/www/html>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>

最后,重新启动Apache守护程序以应用到目前为止配置的所有规则,并通过HTTP协议访问您的域。 因为您在安装时使用Apache发出的自动自签名证书对,所以证书不受浏览器的限制,应在浏览器中显示错误警告。

systemctl restart apache2

HTTPS://yourdomain.tld

接受警告以接受不受信任的证书并继续重定向到Apache默认网页。

如果UFW防火墙应用程序阻止到HTTPS端口的传入网络连接,则应添加新规则以允许HTTPS流量通过发出以下命令来通过防火墙。

ufw allow ‘WWW Full’

要么

ufw allow 443/tcp

如果iptables是为在网络级别保护Debian系统而安装的默认防火墙应用程序,请添加以下规则以允许防火墙中的端口443入站流量,以便访问者可以浏览您的域名。

iptables -I INPUT -p tcp --destination-port 443 -j ACCEPT
netfilter-persistent save
systemctl restart netfilter-persistent
systemctl status netfilter-persistent

最后,要显示所有服务器PHP变量,请执行以下命令创建PHP信息文件,并通过访问以下URL中的浏览器访问PHP信息脚本文件来检查PHP时区是否已正确配置,如下所示图片。 向下滚动到日期设置以检查PHP时区配置。

echo '<?php phpinfo(); ?>'| tee /var/www/html/info.php

HTTPS://domain.tld/info.php

接下来,在创建Moodle存储信息所需的数据库之前,首先我们需要对MariaDB服务器进行一些更改并设置正确的字符集。 打开MariaDB客户端配置文件,并在[client]指令后添加以下行,如下面的示例所示:

nano /etc/mysql/mariadb.conf.d/50-client.cnf
[client]
# Default is Latin1, if you need UTF-8 set this (also in server section)
default-character-set = utf8mb4

接下来,打开mysql.cnf文件并在[mysql]语句后添加与上面相同的行:

nano /etc/mysql/conf.d/mysql.cnf

mysql.cnf文件摘录:

default-character-set = utf8mb4

打开以编辑MariaDB服务器配置文件,并在[mysqld]语句之后添加以下行,以确保MySQL引擎innodb使用Barracuda文件格式和utf8mb4字符集。

nano /etc/mysql/mariadb.conf.d/50-server.cnf

50-server.cnf文件摘录:

[mysqld]
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix

character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
skip-character-set-client-handshake

为了将目前为止所做的所有更改应用于数据库,请重新启动MySQL守护程序,并通过发出以下命令来验证服务是否正在运行。

systemctl restart mysql
systemctl status mysql

最后,通过发出以下命令,登录MariaDB数据库控制台并使用用户和密码创建应用程序数据库,该用户和密码将用于管理应用程序数据库。 确保相应地替换数据库名称,用户和密码。

mysql –u root -p
Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1


Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE moodle_db;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on moodle_db.* to 'moodle_user'@'localhost' identified by 'password1234';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye

安装Moodle

在满足所有系统要求以安装Moodle CMS应用程序后,访问Moodle官方下载页面https://download.moodle.org/releases/latest/并通过发出以下命令获取系统中最新的zip压缩存档。

wget https://download.moodle.org/download.php/direct/stable34/moodle-latest-34.zip

zip存档下载完成后,将Moodle zip存档文件解压缩到当前工作目录,并通过发出以下命令列出解压缩的文件。 此外,删除Apache Web服务器安装到webroot路径的默认index.html文件,并删除之前创建的info.php文件。

unzip moodle-latest-34.zip
ls
rm /var/www/html/index.html
rm /var/www/html/info.php

然后,通过发出以下命令将Moodle解压缩目录的所有内容复制到Web服务器文档根路径。 此外,请确保将以下隐藏的点文件复制到webroot路径。

cp -rf moodle/* /var/www/html/
cp -rf moodle/.eslint* /var/www/html/
cp -rf moodle/.gherkin-lintrc /var/www/html/
cp -rf moodle/.jshintrc /var/www/html/
cp -rf moodle/.s* /var/www/html/
cp -rf moodle/.travis.yml /var/www/html/

接下来,为Moodle创建一个级别的数据目录,直到服务器文档根目录并执行以下命令,以便为Apache运行时用户授予对Web根路径和moodle数据目录的完全写入权限。 使用ls命令列出位于/ var / www / html /目录中的应用程序安装文件的权限。

mkdir /var/www/moodledata
chown -R www-data:www-data /var/www/moodledata/
chown -R www-data:www-data /var/www/html/
ls -al /var/www/html/

现在让我们开始通过Web界面安装程序安装Moodle CMS。 打开浏览器并通过HTTPS协议导航到您的服务器IP地址或域名。 在第一个安装屏幕上,选择安装语言,然后按“下一步”按钮继续。

在下一个屏幕上,安装程序将要求您确认Web服务器地址,moodle目录路径和moodle数据目录路径。 将前两个路径变量保留为默认值,并为Moodle Data目录路径添加/ var / www / moodledata ,如下图所示。 点击下一步按钮继续。

在下一个屏幕上,选择MariaDB(native / madiadb)作为数据库驱动程序,然后单击Next按钮继续安装过程。

接下来,添加数据库设置,例如数据库主机,名称,用户和密码。 使用先前为Moodle数据库配置的数据库名称和凭据。

数据库主机应设置为localhost。 添加您自己的数据库表前缀,使用3306作为数据库端口,然后单击Next按钮完成此步骤并继续安装过程。

在下一个屏幕上,阅读Moodle许可条款和条件,然后单击继续按钮以确认许可条款。

接下来,Moodle安装脚本将执行一系列服务器检查,以确定是否满足所有要求以继续安装过程。 检查所有数据库和PHP扩展是否都设置为OK,向下滚动到页面底部,然后单击Continue按钮继续安装过程。

接下来,等待安装程序完成安装一系列模块并再次点击“继续”按钮以进入下一步。

在下一步中,添加Moodle管理员帐户,为此帐户选择一个强密码并填写所有帐户信息,例如名字,姓氏,电子邮件,城市,国家,时区和说明。 当您点击更新个人资料按钮以保存管理员帐户信息时。

接下来,设置完整的站点名称,添加简短的站点名称和首页摘要,向下滚动并按“保存更改”按钮以完成安装过程。

完成安装过程后,您将被重定向到Moodle管理仪表板。 在这里,您可以使用注册表单向Moodle.net门户注册申请。

要访问Moodle前端页面,请打开浏览器并通过HTTPS协议导航到您的服务器IP地址或域名。

最后,返回Debian服务器控制台并通过发出以下命令创建一个位于您的网站文档根路径中的.htaccess文件。

nano /var/www/html/.htaccess

在.htaccess文件中,添加以下行,以便您可以操作本机PHP服务器设置以匹配您自己的服务器资源和配置。

.htaccess文件摘录:

#修改PHP设置

php_value register_globals 1
php_value upload_max_filesize 100M
php_value post_max_size 100M
Options -Indexes

安装cron

为了定期运行发送电子邮件,清理数据库,更新订阅源或其他任务的Moodle维护脚本,通过发出以下命令,将每个10分钟的cron作业添加到每10分钟。

crontab -u www-data -e

添加以下行并保存cronjob。

*/10 * * * * /usr/bin/php7.0 /var/www/html/admin/cli/cron.php  >/dev/null

恭喜! 您已在Debian 9服务器中成功安装并配置了Moodle CMS。 Moodle文档页面可在以下地址找到: https//docs.moodle.org/23/en/Main_page

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏