ArchLinux 2017.10.01: e-LearningプラットフォームのMoodleをインストールする

Table of Contents

1 Moodleをインストールする


  • MYSQL_PASSWDはMySQLで使うrootユーザのパスワードです。
  • MOODLE_PASSWDはMySQLで使うmoodleユーザのパスワードです。
  • MOODLE_FQDNはお使いの環境のFQDNに変更してください。

#!/bin/shset -e[ -z “${MYSQL_PASSWD}” ] && MYSQL_PASSWD=mysql[ -z “${MOODLE_PASSWD}” ] && MOODLE_PASSWD=moodle[ -z “${MOODLE_FQDN}” ] && MOODLE_FQDN=moodle.hiroom2.commysql_install(){ sudo pacman -Sy –noconfirm mariadb # Install database. sudo mysql_install_db –user=mysql –basedir=/usr –datadir=/var/lib/mysql sudo systemctl enable mariadb sudo systemctl start mariadb # Password configuration. cat <<EOF | sudo mysql_secure_installationy${MYSQL_PASSWD}${MYSQL_PASSWD}nyyyEOF cat<<EOF | sudo mysql -uroot -p${MYSQL_PASSWD}CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;GRANT ALL PRIVILEGES ON moodle.* TO moodle@localhost IDENTIFIED BY ‘${MOODLE_PASSWD}’;exitEOF}php_install(){ # Enable PHP extension. sudo pacman -Sy –noconfirm php php-mcrypt sudo sed -i /etc/php/php.ini -e ‘s/^;’ -e ‘s/^;’ -e ‘s/^;’ -e ‘s/^;’ -e ‘s/^;’ -e ‘s/^;’ -e ‘s/^;’ -e ‘s/^;’ -e ‘s/^;opcache.enable=1/opcache.enable=1/g’}moodle_install(){ sudo pacman -Sy –noconfirm git base-devel git clone cd moodle makepkg -s –noconfirm sudo pacman -U –noconfirm ./*.pkg.tar.xz cd .. cd /usr/share/webapps/moodle cat <<EOF | sudo tee config.php<?phpunset($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->wwwroot = ‘https://${MOODLE_FQDN}/moodle’;$CFG->dirroot = ‘/usr/share/webapps/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 pacman -Sy –noconfirm apache php-apache sudo systemctl enable httpd # php configuration. sudo sed -i /etc/httpd/conf/httpd.conf -e ‘s/^LoadModule mpm_event_module/#LoadModule mpm_event_module/g’ -e ‘s/^#LoadModule mpm_prefork_module/LoadModule mpm_prefork_module/g’ cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.confLoadModule php7_module modules/libphp7.soAddHandler php7-script phpInclude conf/extra/php7_module.confEOF # ssl configuration. # Country Name (2 letter code) [AU]: # State or Province Name (full name) [Some-State]: # Locality Name (eg, city) []: # Organization Name (eg, company) [Internet Widgits Pty Ltd]: # Organizational Unit Name (eg, section) []: # Common Name (e.g. server FQDN or YOUR name) []: # Email Address []: cat <<EOF | sudo openssl req -new -x509 -nodes -newkey rsa:4096 -days 1095 -keyout /etc/httpd/conf/server.key -out /etc/httpd/conf/server.crtAUSome-Statecitycompanysection${MOODLE_FQDN}EOF sudo sed -i /etc/httpd/conf/httpd.conf -e ‘s/^#LoadModule ssl_module/LoadModule ssl_module/g’ -e ‘s/^#LoadModule socache_shmcb_module/LoadModule socache_shmcb_module/g’ cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.confInclude conf/extra/httpd-ssl.confEOF # rewrite configuration. sudo sed -i /etc/httpd/conf/httpd.conf -e ‘s/^#LoadModule rewrite_module/LoadModule rewrite_module/g’ cat << EOF | sudo tee /etc/httpd/conf/extra/redirect-to-https.confRewriteEngine OnRewriteCond %{HTTPS} offRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}EOF cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.confInclude conf/extra/redirect-to-https.confEOFcat <<EOF | sudo tee /etc/httpd/conf/extra/moodle.confAlias /moodle /usr/share/webapps/moodle<Directory /usr/share/webapps/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>EOF cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.confInclude conf/extra/moodle.confEOF sudo systemctl restart httpd}moodle_main(){ mysql_install php_install moodle_install apache_install}moodle_main

2 Moodleへアクセスする




Android | Linux | SDL - Narrow Escape