如何在 Ubuntu 22.04 LTS 上使用 LEMP 堆栈安装 Moodle

Linux命令2年前 (2022)发布 AI观察员
116 0 0

Moodle 是一个免费的开源学习管理系统和用 PHP 编写的 CMS。使用 Moodle,您可以创建一个功能齐全的教育和培训课程网站,适合完全在线、混合和面对面的课堂体验。Moodle 平台是高度可定制的,并采用模块化方法来处理功能,因此它可以扩展并适应您的需求。Moodle 派上用场,特别是对于全球各地的远程教育机构,为他们的学习者提供培训材料。如何在 Ubuntu 22.04 LTS 上使用 LEMP 堆栈安装 Moodle

Ubuntu 22.04 LTS Jammy Jellyfish 上安装带有 LEMP 堆栈的 Moodle

apt步骤 1. 首先,通过在终端中运行以下命令,确保所有系统包都是最新的。

sudo apt update
sudo apt upgrade
sudo apt install software-properties-common dirmngr

步骤 2. 安装 LEMP 堆栈。

在开始本教程之前,必须在您的服务器上安装 LEMP 服务器。如果您没有安装 LEMP Stack,您可以在此处按照我们的指南进行操作。

步骤 3. 在 Ubuntu 22.04 上安装 Moodle。

默认情况下,Moodle 在 Ubuntu 22.04 基础存储库中不可用。现在运行以下命令,将 Moodle 的最新稳定版本下载到您的 Ubuntu 系统:

cd /var/www/html
git clone -b MOODLE_400_STABLE git://git.moodle.org/moodle.git moodle

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

mkdir -p /var/www/html/moodledata
chown -R www-data:www-data /var/www/html/moodle
chmod -R 755 /var/www/html/*
chown www-data:www-data /var/www/html/moodledata

步骤 4. 为 Moodle 配置 MariaDB。

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

mysql_secure_installation

像这样配置它:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

接下来,我们需要登录 MariaDB 控制台并为 Moodle 创建一个数据库。运行以下命令:

mysql -u root -p

这将提示您输入密码,因此请输入您的 MariaDB 根密码并按 Enter。登录到数据库服务器后,您需要为 Moodle 安装创建一个数据库:

MariaDB [(none)]> CREATE DATABASE moodle_db;
MariaDB [(none)]> CREATE USER 'moodle_user'@'localhost' IDENTIFIED BY 'your-strong-password';
MariaDB [(none)]> GRANT ALL ON moodle_db.* TO 'moodle_user'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

步骤 6. 为 Moodle 配置 Nginx 虚拟主机。

现在我们创建一个 Nginx 虚拟主机配置文件:

nano /etc/nginx/conf.d/wordpress.conf

添加以下文件:

server {
    listen 80;
    root /var/www/html/moodle;
    index  index.php index.html index.htm;
    server_name  your-domian.com;

    client_max_body_size 500M;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
	
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }	

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }	

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }
}

保存并关闭文件,然后重新启动 Nginx Web 服务器以进行更改:

nginx -t
sudo systemctl restart nginx
sudo systemctl restart php8.1-fpm

步骤 6. 在 Moodle 上启用安全 HTTPS。

首先,我们使用以下命令在 Ubuntu 22.04 上安装Certbot :

sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

完成安装 Certbot 后,现在我们使用以下命令为 Nginx 设置 Certbot:

sudo apt install python3-certbot-nginx

接下来,运行以下命令开始创建证书:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email admin@your-domain.com -d www.your-domain.com

输出:

-------------------------------------------------------------------------------
Congratulations! You have successfully enabled https://domain.com and https://www.your-domain.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=your-domain.com
https://www.ssllabs.com/ssltest/analyze.html?d=www.your-domain.com
-------------------------------------------------------------------------------

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/your-domain.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/your-domain.comm/privkey.pem
Your cert will expire on 2022-07-20. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

Let’s Encrypt 证书的有效期为 90 天,强烈建议在证书到期前更新证书。要测试此更新过程是否正常工作,您可以运行:

sudo certbot renew --dry-run

输出:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/your-domain.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Account registered.
Simulating renewal of an existing certificate for your-domain.com and www.your-domain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded: 
  /etc/letsencrypt/live/domain.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

步骤 7. 配置防火墙。

Ubuntu 22.04ufw默认运行防火墙。通过端口80HTTP 和443HTTPS 启用连接:

sudo ufw allow 'Nginx FULL'
sudo ufw enable
sudo ufw status

步骤 8. 访问 Moodle Web 界面。

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

如何在 Ubuntu 22.04 LTS 上使用 LEMP 堆栈安装 Moodle 如何在 Ubuntu 22.04 LTS 上使用 LEMP 堆栈安装 Moodle

感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装带有 LEMP 的 Moodle。如需更多帮助或有用信息,我们建议您查看Moodle 官方网站

© 版权声明

相关文章

天猫U特购  京东优惠购        京东优惠    天猫优惠