e-LearningプラットフォームのMoodleをインストールする手順を記載します。
Table of Contents
1 Moodleをインストールする
- この記事ではhttpsの為にデフォルトのSSL/TLS証明書を使っています。別にSSL/TLS証明書を用意している場合はそちらをお使いください。
- httpではなくhttpを使用する場合は、 /etc/apache2/sites-available/moodle.confにて、443を80にして SSLXXXのディレクティブを削除してください。
- MOODLE_FQDNはお使いの環境のFQDNに変更してください。
- MOODLE_PASSWDはMySQLで使うmoodleユーザのパスワードです。
#!/bin/sh -e PHP_VERSION=7.2 [ -z "${MYSQL_PASSWD}" ] && \ MYSQL_PASSWD=mysql [ -z "${MOODLE_FQDN}" ] && \ MOODLE_FQDN=$(hostname -f) [ -z "${MOODLE_PASSWD}" ] && \ MOODLE_PASSWD=moodle mysql_install() { sudo apt install -y default-mysql-server cat <<EOF | sudo tee -a /etc/mysql/my.cnf [client] default-character-set = utf8mb4 [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] default-character-set = utf8mb4 EOF sudo systemctl enable mysql sudo systemctl restart mysql cat <<EOF | sudo mysql_secure_installation y ${MYSQL_PASSWD} ${MYSQL_PASSWD} n y y y EOF cat<<EOF | sudo mysql -uroot -p${MYSQL_PASSWD} CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE \ utf8mb4_unicode_ci; GRANT ALL PRIVILEGES ON moodle.* TO moodle@localhost IDENTIFIED BY '${MOODLE_PASSWD}'; exit EOF } moodle_install() { # The moodle needs the following php extensions. # curl iconv mbstring openssl tokenizer xmlrpc soap ctype zip zlib # gd simplexml spl pcre dom xml xmlreader intl json hash fileinfo. # # libapache2-mod-php has php-mbstring and php-xml. sudo apt install -y php php-mysql php-curl php-xmlrpc php-soap \ php-gd php-intl php-json php-xml php-zip php-mbstring sudo apt install -y git sudo mkdir -p /var/lib/moodle cd /usr/share sudo git clone https://github.com/moodle/moodle cd moodle sudo git checkout v3.5.1 -b v3.5.1 cat <<EOF | sudo tee config.php <?php unset(\$CFG); global \$CFG; \$CFG = new stdClass(); \$CFG->dbtype = 'mariadb'; \$CFG->dbhost = 'localhost'; \$CFG->dbname = 'moodle'; \$CFG->dbuser = 'moodle'; \$CFG->dbpass = '${MOODLE_PASSWD}'; \$CFG->prefix = 'mdl_'; \$CFG->dboptions = array('dbcollation' => 'utf8mb4_unicode_ci',); \$CFG->wwwroot = 'https://${MOODLE_FQDN}/moodle'; \$CFG->dirroot = '/usr/share/moodle'; \$CFG->dataroot = '/var/lib/moodle'; \$CFG->directorypermissions = 0750; \$CFG->admin = 'admin'; \$CFG->pathtodu = '/usr/bin/du'; \$CFG->unzip = '/usr/bin/unzip'; \$CFG->zip = '/usr/bin/zip'; \$CFG->respectsessionsettings = true; \$CFG->disableupdatenotifications = true; \$CFG->enablehtmlpurifier = true; if (file_exists("\$CFG->dirroot/lib/setup.php")) { include_once("\$CFG->dirroot/lib/setup.php"); } else { if (\$CFG->dirroot == dirname(__FILE__)) { echo "<p>Could not find this file: \$CFG->dirroot/lib/setup.php</p>"; echo "<p>Are you sure all your files have been uploaded?</p>"; } else { echo "<p>Error detected in config.php</p>"; echo "<p>Error in: \\\$CFG->dirroot = '\$CFG->dirroot';</p>"; echo "<p>Try this: \\\$CFG->dirroot = '".dirname(__FILE__)."';</p>"; } die; } EOF } apache_install() { sudo apt install -y apache2 libapache2-mod-php sudo chown -R www-data:root /var/lib/moodle cat <<EOF | sudo tee /etc/apache2/sites-available/moodle.conf <VirtualHost _default_:443> SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key Alias /moodle /usr/share/moodle <Directory /usr/share/moodle> Options FollowSymLinks MultiViews AllowOverride None Require all granted php_flag magic_quotes_gpc Off php_flag magic_quotes_runtime Off php_flag file_uploads On php_flag session.auto_start Off php_flag session.bug_compat_warn Off php_value upload_max_filesize 2M php_value post_max_size 2M </Directory> </VirtualHost> EOF sudo a2enmod ssl sudo a2enmod php${PHP_VERSION} sudo a2ensite moodle sudo systemctl enable apache2 sudo systemctl restart apache2 } moodle_main() { mysql_install moodle_install apache_install } moodle_main
2 Moodleへアクセスする
以下のURLにアクセスしてMoodleをセットアップします。
https://<server>/moodle