このページは更新が必要です。 更新を行い、完了したらこのテンプレートを削除してください。
これらの手順はMoodle 5.3向けに更新する必要があります。更新されるまでは、以下の点に注意してください:
- データベースバージョン: Moodle 5.3にはMariaDB 11.4以降が必要ですが、Ubuntu 24.04ではデフォルトでMariaDB 10.11がインストールされるため、インストールは動作環境チェックで停止します。
- Ubuntuバージョン: Ubuntu 26.04は回避策になりません。Ubuntu 26.04のデフォルトのPHPは8.5ですが、Moodle 5.3がサポートしているのはPHP 8.3および8.4のみです。
詳細については、Moodle 5.3のサーバ要件を参照してください。
Moodleのインストール
このガイドでは、sudoまたはrootアクセス権のあるLinux Ubuntu 24サーバが必要です。このページのコマンドはすべてテキストベースのため、グラフィカルインタフェースを備えたデスクトップは必要ありません。各ステップでは、行う必要がある作業を説明した後、そのステップを実行するためのコマンドを示します。処理の各行を理解している場合を除き、色付きのステップ全体をコピーしてください。
ウェブサーバの選択肢として、ApacheまたはNginxを示しています。どちらか一方のみをインストールし、両方はインストールしないでください。どちらも良い選択肢です。Apacheはコミュニティのサポートが充実しており、Nginxはアクセスの多いサイトにより適している場合があります。
この手順を完了すると、動作環境チェックおよびセキュリティチェックがすべて合格した状態で、管理者としてMoodleにログインできるはずです。
基本パッケージの更新とインストール
Moodleには、https://moodledev.io/general/releases/5.3#server-requirements に記載されているとおり、ウェブサーバ、データベースおよびPHPスクリプト言語が必要です。
# An admin email needs to be set for Moodle
while true; do read -p "Enter email: " USER_EMAIL; [[ "$USER_EMAIL" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]] && break || echo "Invalid email address. Try again."; done
# Set your domain name or IP address as a temporary variable as it will be needed several times in the installation.
while true; do read -p "Enter the web address (eg domain name mymoodle123.com or IP address 192.168.1.1.): " WEBSITE_ADDRESS; [[ ! "$WEBSITE_ADDRESS" =~ ^https?:// ]] && [[ "$WEBSITE_ADDRESS" =~ ^([A-Za-z0-9.-]+\.[A-Za-z]{2,4}|([0-9]{1,3}\.){3}[0-9]{1,3})$ ]] && break || echo "Invalid domain name or IP address. Try again."; done
# Default paths,change if desired
MOODLE_PATH="/srv/www"
MOODLE_DATA_FOLDER="/var/www/data"
# End if defaukt variables
MOODLE_CODE_FOLDER="$MOODLE_PATH/moodle"
sudo mkdir -p $MOODLE_PATH
sudo mkdir -p $MOODLE_DATA_FOLDER
PROTOCOL="http://";
# Refresh and download latest versions of all packages
sudo apt-get update && sudo apt upgrade -y
# Get php-fpn and required php extensions using the package manager apt-get
sudo apt-get install -y php8.3-fpm php8.3-cli php8.3-curl php8.3-zip php8.3-gd php8.3-xml php8.3-intl php8.3-mbstring php8.3-xmlrpc php8.3-soap php8.3-bcmath php8.3-exif php8.3-ldap php8.3-mysql
# Database and packgages required by Moodle
sudo apt-get install -y unzip mariadb-server mariadb-client ufw nano graphviz git clamav ghostscript composer cron
# Check Moodle git page for latest point release
MOODLE_VERSION=$(sudo -u www-data git ls-remote --tags https://github.com/moodle/moodle.git 'refs/tags/v5.3.*' | awk '{print $2}' | sed -E 's#refs/tags/##; s/\^\{\}$//' | grep -E '^v5\.3\.[0-9]+$' | sort -V | tail -n 1)
ウイルスチェッカのインストール
ウイルスチェッカは本番サイトに不可欠であり、見落とされがちなため、ここでインストールして設定しておくのが最善です。
sudo apt-get install -y clamav clamdscan clamav-daemon apparmor-utils acl
echo "clamav-freshclam clamav-freshclam/internet_method select daemon" | sudo debconf-set-selections
sudo DEBIAN_FRONTEND=noninteractive dpkg-reconfigure clamav-freshclam
# Add clamav to the web server group
sudo usermod -a -G www-data clamav
# Relax AppArmor profiling restrictions for the daemon binary
sudo aa-disable /usr/sbin/clamd
sudo systemctl reload apparmor
# Set file ACLs so clamav can seamlessly check temporary upload folders
sudo setfacl -Rdm clamav:rwx /tmp
sudo chmod +x /usr/bin/clamdscan
sudo systemctl enable clamav-daemon
sudo systemctl start clamav-daemon
ウェブサーバのインストール
ウェブサーバの選択肢として、ApacheまたはNginxを示しています。オプション1またはオプション2のどちらか一方を選択し、両方は選択しないでください。どちらも良い選択です。Apacheはコミュニティのサポートが充実しており、Nginxはアクセスの多いサイトにより適している場合があります。ルータへの移行とr.phpの導入により、この作業はより複雑になってきています。また、このセクションでは、サイトをhttpsにするためにLetsEncryptを呼び出しますが、これはウェブアドレスとしてドメイン名を入力した場合のみです。
オプション1:ウェブサーバとしてApacheをインストールする
# Install Apache and module for FastCGI protocol
sudo apt-get install -y apache2 libapache2-mod-fcgid
# Enable required Apache modules for PHP-FPM and rewriting
sudo a2enmod proxy_fcgi setenvif rewrite
# Create Moodle Apache site config with fallback and PHP-FPM socket
sudo tee /etc/apache2/sites-available/moodle.conf > /dev/null <<EOF
<VirtualHost *:80>
ServerName $WEBSITE_ADDRESS
ServerAlias www.$WEBSITE_ADDRESS
DocumentRoot $MOODLE_CODE_FOLDER/public
DirectoryIndex index.php index.html
<Directory $MOODLE_PATH>
Options FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
# Enable PathInfo processing for Moodle clean URLs
AcceptPathInfo On
# Security Rewrite Rules
RewriteEngine On
RewriteRule "(\/vendor\/)" - [L,R=404]
RewriteRule "(\/node_modules\/)" - [L,R=404]
RewriteRule "(^|/)\.(?!well-known\/)" - [L,R=404]
RewriteRule "(composer\.json)" - [L,R=404]
RewriteRule "(\.lock)" - [L,R=404]
RewriteRule "(\/environment.xml)" - [L,R=404]
RewriteRule "(\/lib\/classes)" - [L,R=404]
RewriteRule "(\/install.xml)" - [L,R=404]
RewriteRule "(\/README)" - [L,R=404]
RewriteRule "(\/readme)" - [L,R=404]
RewriteRule "(\/moodle_readme)" - [L,R=404]
RewriteRule "(\/upgrade\.txt)" - [L,R=404]
RewriteRule "(phpunit\.xml\.dist)" - [L,R=404]
RewriteRule "(\/tests\/behat\/)" - [L,R=404]
RewriteRule "(\/fixtures\/)" - [L,R=404]
RewriteRule "(\/upgrade\.txt|UPGRADING\.md|UPGRADING\-CURRENT\.md)" - [L,R=404]
# Enable fallback routing for URLs not matching files/directories
FallbackResource /r.php
</Directory>
# PHP-FPM 8.3 FastCGI handler via Unix socket
<FilesMatch "\.php$">
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost"
</If>
</FilesMatch>
# Log files
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF
# Enable the new Moodle site and disable the default site if desired
sudo a2ensite moodle.conf
sudo a2dissite 000-default.conf
# Reload Apache to apply all changes
sudo systemctl reload apache2
# Enable and start PHP 8.3 FPM service
sudo systemctl enable --now php8.3-fpm
# Adjust PHP settings for both Apache and CLI
php_ini_apache="/etc/php/8.3/fpm/php.ini"
php_ini_cli="/etc/php/8.3/cli/php.ini"
sudo sed -i 's/^[[:space:]]*;*[[:space:]]*max_input_vars[[:space:]]*=.*/max_input_vars = 5000/' "$php_ini_apache"
sudo sed -i 's/^[[:space:]]*;*[[:space:]]*max_input_vars[[:space:]]*=.*/max_input_vars = 5000/' "$php_ini_cli"
sudo sed -i 's/^\s*post_max_size\s*=.*/post_max_size = 256M/' "$php_ini_apache"
sudo sed -i 's/^\s*post_max_size\s*=.*/post_max_size = 256M/' "$php_ini_cli"
sudo sed -i 's/^\s*upload_max_filesize\s*=.*/upload_max_filesize = 256M/' "$php_ini_apache"
sudo sed -i 's/^\s*upload_max_filesize\s*=.*/upload_max_filesize = 256M/' "$php_ini_cli"
# Reload PHP-FPM to apply PHP configuration changes
sudo systemctl reload php8.3-fpm
# Check if the string contains at least one letter (a-z or A-Z)
if [[ "$WEBSITE_ADDRESS" =~ [a-zA-Z] ]]; then
sudo apt install certbot python3-certbot-apache -y
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo certbot --apache \
--non-interactive \
--agree-tos \
--email "$USER_EMAIL" \
-d "$WEBSITE_ADDRESS" \
--redirect
PROTOCOL="https://";
fi
これでApacheウェブサーバがインストールされました。インストールを続けるには、「Moodleコード」に進んでください。
オプション2:ウェブサーバとしてNginxをインストールする
Apacheをすでにインストールしている場合は、Nginxをインストールしないでください!
if [ ! -f /etc/apache2/sites-available/moodle.conf ]; then
sudo apt-get update && sudo apt-get install -y nginx
# Set up the configuration file including the fallback required for the router
# Using tee allows the file to be written in a single command.
sudo tee /etc/nginx/sites-available/moodle.conf > /dev/null <<EOF
server {
listen 80;
server_name $WEBSITE_ADDRESS www.$WEBSITE_ADDRESS;
root $MOODLE_CODE_FOLDER/public;
index index.php index.html index.htm;
autoindex off;
location / {
try_files \$uri \$uri/ /index.php?\$args /r.php;
}
location ~ ^/lib/.*\.php\$ {
try_files \$uri /r.php?\$query_string;
fastcgi_split_path_info ^(.+\.php)(/.+)\$;
fastcgi_param PATH_INFO \$fastcgi_path_info;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}
location ~ [^/]\.php(/|\$) {
fastcgi_split_path_info ^(.+\.php)(/.+)\$;
fastcgi_param PATH_INFO \$fastcgi_path_info;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED \$document_root\$fastcgi_path_info;
}
location ~ /\.(?!well-known).* {
return 404;
}
location ~ (/vendor/|/node_modules/|composer\.json|/readme|/README|readme\.txt|/upgrade\.txt|/UPGRADING\.md|db/install\.xml|/fixtures/|/behat/|phpunit\.xml|\.lock|environment\.xml) {
deny all;
return 404;
}
}
EOF
# Recognise the new config file
sudo ln -sf /etc/nginx/sites-available/moodle.conf /etc/nginx/sites-enabled/moodle.conf
sudo systemctl reload nginx
# Make necessary changes to the php configuration required by Moodle
sudo sed -i 's/^;*max_input_vars =.*/max_input_vars = 5000/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/^;*max_input_vars =.*/max_input_vars = 5000/' /etc/php/8.3/cli/php.ini
sudo sed -i 's/^post_max_size =.*/post_max_size = 256M/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/^post_max_size =.*/post_max_size = 256M/' /etc/php/8.3/cli/php.ini
sudo sed -i 's/^upload_max_filesize =.*/upload_max_filesize = 256M/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/^upload_max_filesize =.*/upload_max_filesize = 256M/' /etc/php/8.3/cli/php.ini
sudo systemctl reload php8.3-fpm
# Check if the string contains at least one letter (a-z or A-Z)
if [[ "$WEBSITE_ADDRESS" =~ [a-zA-Z] ]]; then
sudo apt-get install -y certbot python3-certbot-nginx
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo certbot --nginx \
--non-interactive \
--agree-tos \
--email "$USER_EMAIL" \
-d "$WEBSITE_ADDRESS" \
--redirect
PROTOCOL="https://"
fi
fi
gitを使用したMoodleコードの取得
gitはバージョン管理システムであり、最新のMoodleコードをダウンロードしてディレクトリに展開する最も簡単な方法です。また、パッチを適用して最新の状態に保つこともはるかに簡単になります。
#Clone to the Moodle code folder
sudo git clone -b $MOODLE_VERSION https://github.com/moodle/moodle.git $MOODLE_CODE_FOLDER
sudo chown -R www-data:www-data $MOODLE_CODE_FOLDER
cd $MOODLE_CODE_FOLDER
CACHE_DIR="/var/www/.cache/composer"
sudo mkdir -p "$CACHE_DIR"
sudo chown -R www-data:www-data "$CACHE_DIR"
sudo chmod -R 750 "$CACHE_DIR"
sudo -u www-data COMPOSER_CACHE_DIR="$CACHE_DIR" composer install --no-dev --classmap-authoritative
sudo chown -R www-data:www-data vendor
sudo chmod -R 755 $MOODLE_CODE_FOLDER
Moodle固有の要件
Moodleは、ウェブサーバのみがアクセスできる特定のディレクトリにファイルを保存する必要があります。また、PHPの設定をいくつか変更し、cronタスクを設定する必要があります。これはテキストエディタを使用して行うこともできますが、echoと、テキスト置換ツールであるsedを使用すると作業が簡単になります。
# Create the moodledata directory outside your web server's document root
sudo mkdir -p $MOODLE_DATA_FOLDER/moodledata
# Set the webserver as the owner and group recursively ( for both the files and contents)
sudo chown -R www-data:www-data $MOODLE_DATA_FOLDER/moodledata
# Set the moodledata directory permissions so only the web server can read, write, and access them.
sudo find $MOODLE_DATA_FOLDER/moodledata -type d -exec chmod 700 {} \;
# Set the moodledata file permissions so only the web server can read and write them.
sudo find $MOODLE_DATA_FOLDER/moodledata -type f -exec chmod 600 {} \;
# Call the cron.php in the moodle admin directory to run every minute.
echo "* * * * * /usr/bin/php $MOODLE_CODE_FOLDER/admin/cli/cron.php >/dev/null" | sudo crontab -u www-data -
データベースおよびユーザの作成
Moodleには、データベースと、すべての権限を持つユーザが必要です
# Create a random password for the user who will access the moodle database
MYSQL_MOODLEUSER_PASSWORD=$(openssl rand -base64 6)
# Create a new database named moodle with the utf8mb4 character set and utf8mb4_unicode_ci collation.
sudo mysql -e "CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
# Create a new MySQL user moodleuser with a password
sudo mysql -e "CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY '$MYSQL_MOODLEUSER_PASSWORD';"
# Grant privileges on the moodle database to the moodleuser to allow localhost access.
sudo mysql -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER ON moodle.* TO 'moodleuser'@'localhost';"
# Reloads privilege tables
sudo mysql -e "FLUSH PRIVILEGES;"
コマンドラインからのMoodleの設定
最後のステップはブラウザを使用して行うこともできますが、インストールを完了するために必要な情報はすべて揃っています
MOODLE_ADMIN_PASSWORD=$(openssl rand -base64 8)
sudo chmod -R 0777 $MOODLE_CODE_FOLDER
cd $MOODLE_PATH
sudo -u www-data /usr/bin/php $MOODLE_CODE_FOLDER/admin/cli/install.php --non-interactive --lang=en --wwwroot="$PROTOCOL$WEBSITE_ADDRESS" --dataroot=$MOODLE_DATA_FOLDER/moodledata --dbtype=mariadb --dbhost=localhost --dbname=moodle --dbuser=moodleuser --dbpass="$MYSQL_MOODLEUSER_PASSWORD" --fullname="Generic Moodle" --shortname="GM" --adminuser=admin --summary="" --adminpass="$MOODLE_ADMIN_PASSWORD" --adminemail=$USER_EMAIL --agree-license
echo "Moodle installation completed successfully. You can now log on to your new Moodle at $PROTOCOL$WEBSITE_ADDRESS as admin with $MOODLE_ADMIN_PASSWORD and complete your site registration"
echo "Remember to change the admin email, name and shortname using the browser in your new Moodle"
sudo find $MOODLE_CODE_FOLDER -type d -exec chmod 755 {} \;
sudo find $MOODLE_CODE_FOLDER -type f -exec chmod 644 {} \;
# nginx needs slash arguments set
sudo sed -i "/require_once(__DIR__ . '\/lib\/setup.php');/i \$CFG->slasharguments = true;\n\$CFG->routerconfigured = true;\n\$CFG->preventexecpath = true;" $MOODLE_CODE_FOLDER/config.php
sudo -u www-data php $MOODLE_CODE_FOLDER/admin/cli/cfg.php --name=antiviruses --set=clamav
sudo chmod 444 $MOODLE_CODE_FOLDER/public/config.php
sudo chmod 444 $MOODLE_CODE_FOLDER/config.php
開発用データベースの本番用への準備
本番用データベースには、学生の提出物が含まれます。学生のデータを不正アクセスから保護し、データの損失を防ぐために、追加のステップが必要です。
パーミッションの確認
パーミッションは、Linuxでディレクトリおよびフォルダの読み取り、書き込みおよび実行を制御するために使用されます
# Reset the permissions on /var/www/html/moodle directories to read, write and execute for the webserver, read and execute for group and others
sudo find /var/www/html/moodle -type d -exec chmod 755 {} \;
# Reset the permissions on /var/www/html/moodle files to read, write for the webserver, read only for group and other
sudo find /var/www/html/moodle -type f -exec chmod 644 {} \
データベースのrootパスワードの設定
# Run the mariadb-secure-installation script to strengthen security by setting a root password, removing anonymous users, disabling remote root login, deleting the test database, and reloading privileges.
# Don't forget to write down the root database in a safe place.
sudo mariadb-secure-installation
ファイアウォールの設定と有効化
# Allow SSH (port 22) for remote access
sudo ufw allow 22/tcp
# Enable the UFW firewall with confirmation
sudo ufw --force enable
# Set default policy to deny all incoming connections
sudo ufw default deny incoming
# Set default policy to allow all outgoing connections
sudo ufw default allow outgoing
# Allow HTTP traffic on port 80
sudo ufw allow www
# Allow full access for Apache (HTTP and HTTPS)
sudo ufw allow 'Apache Full'
httpから暗号化されたhttpsプロトコルへの変換
注:このステップでhttpsを使用するには、ドメイン名が必要です。まだ取得していない場合は取得してください。
MoodleサイトでHTTPではなくHTTPSを使用すると、データ転送の暗号化とプライバシー規制への準拠という重要なセキュリティ上の利点が得られます。また、サイトでHTTP接続を使用している場合、Moodleの一部の機能が正しく動作しなかったり、ブロックされたりする場合があります。
Apache版
# Install package and run the certbot program
sudo apt-get install certbot python3-certbot-apache
# Call the certbot and answer the prompts
sudo certbot --apache
# Check the new configuration is correct
sudo apache2ctl configtest
# Restart Apache
sudo systemctl reload apache2
Nginx版
sudo apt-get update
# Install needed packages
sudo apt-get install certbot python3-certbot-nginx
# Run the certbot script
sudo certbot --nginx
# Test your new configuration
sudo nginx -t
# Reload the webserver to allow changes to take effect
sudo systemctl reload nginx
プロトコルを変更した後は、参照を更新する必要があります。
#Replace oldsitehost ( ie http://yourdomain.com) with newsitehost ( ie https://yourdomain.com)
cd /var/www/html/moodle
sudo php admin/tool/replace/cli/replace.php --search=//oldsitehost --replace=//newsitehost --shorten --non-interactive
SSH鍵
SSH鍵は公開鍵と秘密鍵のペアで構成され、Secure Shell(SSH)プロトコルを使用して、パスワードなしで安全に認証するために使用されます。鍵は一般的なパスワードよりもはるかに長く複雑なため、総当たり攻撃や推測に対して非常に強い耐性があります。コピーするのは公開鍵(id_rsa.pub)のみです。秘密鍵は決して共有しないでください。
Windowsユーザの場合:
- 「設定 > アプリと機能 > オプション機能」を開きます。一覧で「OpenSSH クライアント」を探します
- インストールされていない場合は、「機能の追加」をクリックし、「OpenSSH クライアント」を見つけてインストールします。
Linuxユーザの場合
- 手元のマシン(サーバではありません)でターミナルを開きます
# Generate the SSH key pair by running the key generation (without sudo so the keys are stored in ~/.ssh/)
ssh-keygen
# Press Enter to accept the default key save location (usually C:\Users\your_username\.ssh\id_rsa for Windows users, ~/.ssh\id_rsa for Linux)
# When prompted, optionally enter a secure passphrase for extra protection or press Enter to leave it empty.
# Copy your public key to the remote server's ~/.ssh/authorized_keys file, permissions will be sett automatically
ssh-copy-id user@server_address
# Try to log in, It should not ask you for a password.
rootのSSHアクセスの削除
セキュリティのため、常に昇格した権限を持つユーザ(sudoユーザ)としてログインしてください。本番サーバにrootとしてログインすることは決してせず、サーバからrootのSSHアクセスを削除してください。
# If you don't already have a sudo user, as root, create a new user 'user1' with home directory and prompt for password
# Enter and confirm a password for user1. User details are optional
adduser user1
# Add 'user1' to the sudo group for administrative privileges
usermod -aG sudo user1
新しいsudoユーザとしてサーバにSSH接続できることを確認してください!確認できるまで、別のターミナルを開いたままにしておきます。
# Backup sshd_config before modifying
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
# Open the ssh config file
sudo nano /etc/ssh/sshd_config
# Change the line containing PermitRootLogin to PermitRootLogin no
# Restart SSH service to apply changes
sudo systemctl restart ssh
Ubuntuを最新の状態に保つ
セキュリティパッチの適用は自動化できます。
sudo apt install unattended-upgrades
# Edit or review /etc/apt/apt.conf.d/20auto-upgrades:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
これらの行のデフォルトは「1」(毎日更新)です。その他の値:「7」(毎週)、「0」(無効)
- APT::Periodic::Update-Package-Lists "1";
- APT::Periodic::Unattended-Upgrade "1";
# Edit the config file to customize what will be upgraded
# Uncomment as needed
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";
ログ /var/log/unattended-upgrades/ を確認してください
SQLバックアップ
本番環境のMoodleでは、日付付きのSQLバックアップを毎日自動で作成するよう設定する必要があります。ダンプは大きくなる場合があるため、定期的に削除する必要があります。
# Create MySQL backup user and grant privileges to lock tables (better security than using root or moodleuser roles)
BACKUP_USER_PASSWORD=$(openssl rand -base64 6)
mysql <<EOF
CREATE USER 'backupuser'@'localhost' IDENTIFIED BY '${BACKUP_USER_PASSWORD}';
GRANT LOCK TABLES, SELECT ON moodle.* TO 'backupuser'@'localhost';
FLUSH PRIVILEGES;
EOF
# Create a configuration file for root with the backup user credentials (to avoid the password being visible in the SQL backup call)
cat > /root/.my.cnf <<EOF
[client]
user=backupuser
password=${BACKUP_USER_PASSWORD}
EOF
# Set the configuration file permissions to read and write for root only
chmod 600 /root/.my.cnf
# Setup backup directory with read, write and execute permissions for root only
mkdir -p /var/backups/moodle && chmod 700 /var/backups/moodle && chown root:root /var/backups/moodle
# Set up two daily cron jobs, one to dump the database and the other to remove dumps more than a set number of days old (hardcoded to 7)
(crontab -l 2>/dev/null; echo "0 2 * * * mysqldump --defaults-file=/root/.my.cnf moodle > /var/backups/moodle/moodle_backup_\$(date +\%F).sql") | crontab -
(crontab -l 2>/dev/null; echo "0 3 * * * find /var/backups/moodle -name \"moodle_backup_*.sql\" -type f -mtime +7 -delete") | crontab -
サーバでのアンチウイルスの設定
Moodleサーバでアップロードされたファイルのウイルスをスキャンするには、アンチウイルスプラグインを設定できます。
ClamAV®はUbuntuにインストールできます。Ubuntuで次のコマンドを実行して、アンチウイルスサーバをインストールします:
# sudo apt install -y clamav
これにより、ファイルを1つずつスキャンするclamスキャナがインストールされます。有効にするには、サイト管理 > プラグイン > アンチウイルスプラグイン > アンチウイルスプラグインを管理する > ClamAVアンチウイルスに移動し、目のアイコンを開いてプラグインを「有効」にします。

ClamAV®の「設定」に次のコマンドを追加します:
/usr/bin/clamscan
注:このスキャナは、アップロードされたファイルごとにClamAV®プロセスを1回起動します。Moodleサイトで多数のファイルが同時にアップロードされる場合は、ClamAV®デーモンプロセスを有効にするとよいでしょう。そのためには、ClamAV®デーモンをインストールします:
# sudo apt install -y clamav-daemon
サイトでデーモンプロセスが実行されたら、Moodleの設定でClamAV®コマンドを次のように変更できます:
/usr/bin/clamdscan
以前のMoodleブランチの場合: 「アップロードファイルにClamAVを使用する」をチェックします 「ClamAVパス」:/usr/bin/clamscan 「隔離ディレクトリ」:/var/quarantine
「変更を保存する」