A newer version of this doc was added to Vultr docs.
Moodle is an open-source Learning Platform or course management system (CMS) - a free Open Source software package designed to help educators create effective online courses.
This tutorial will cover the process of installing Moodle 3.2.x on a CentOS 7 server.
Log in to your server via SSH using the sudo user to install epel
, update the system, and restart to apply the updates.
sudo yum install epel-release -y
sudo yum update -y && sudo shutdown -r now
sudo yum install httpd -y
In production, you should remove the pre-set Apache welcome page:
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
Prevent Apache from listing web directory files to visitors:
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
Start the Apache service and enable it to auto-start on boot
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
Moodle stores all its data to a MySQL Database. MariaDB is a drop-in replacement for MySQL and we will be installing the latest stable version, MariaDB 10.1.
In order to create the MariaDB 10.1 YUM repo file, copy the below code segment to your SSH terminal console and then press the Enter
button:
cat <<EOF | sudo tee -a /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.1 CentOS repository list - created 2017-01-14 03:11 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
sudo yum install MariaDB-server MariaDB-client -y
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
sudo /usr/bin/mysql_secure_installation
Answer questions as below, and make sure to use a strong MariaDB root password instead of the sample one showed beneath:
Enter
buttonY
your-root-password
your-root-password
Y
Y
Y
Y
Log into the MySQL shell as root
:
mysql -u root -p
Type the MariaDB root password you set earlier when prompted.
In the MySQL shell, create a database moodle
, a database user moodleuser
, the database user's password yourpassword
as follows.
Note: For security purposes, you should replace the sample password yourpassword
mentioned above with your own ones.
CREATE DATABASE moodle DEFAULT CHARACTER SET UTF8 COLLATE utf8_unicode_ci;
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
PHP is also required by Moodle. In order to achieve better performance, you can install PHP 7.1 and several PHP 7.1 extensions as follows:
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install mod_php71w php71w-common php71w-mbstring php71w-xmlrpc php71w-soap php71w-gd php71w-xml php71w-intl php71w-mysqlnd php71w-cli php71w-mcrypt php71w-ldap -y
At the time of writing, the latest stable release of Moodle is Moodle 3.2.1
. Download and unzip the Moodle 3.2.1
archive as follows:
Note: You can always get the download URL of the latest stable release of Moodle from its official download page.
cd
wget https://download.moodle.org/download.php/direct/stable32/moodle-3.2.1.tgz
sudo tar -zxvf moodle-3.2.1.tgz -C /var/www/html
sudo chown -R root:root /var/www/html/moodle
For security purposes, this data directory should be outside of the web root directory:
sudo mkdir /var/www/moodledata
sudo chown -R apache:apache /var/www/moodledata
sudo chmod -R 755 /var/www/moodledata
Note: Remember to replace the values of ServerAdmin
, ServerName
, ServerAlias
, Errorlog
, and CustomLog
with your own ones.
cat <<EOF | sudo tee -a /etc/httpd/conf.d/moodle.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/moodle/
ServerName moodle.example.com
ServerAlias www.moodle.example.com
<Directory /var/www/html/moodle/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/moodle.example.com-error_log
CustomLog /var/log/httpd/moodle.example.com-access_log common
</VirtualHost>
EOF
sudo /usr/bin/php /var/www/html/moodle/admin/cli/install.php
When prompted, provide necessary information according to the specific settings to your setup. Summary information are listed below:
== Choose a language ==
en - English (en)
? - Available language packs
type value, press Enter to use default value (en)
: en
-------------------------------------------------------------------------------
== Data directories permission ==
type value, press Enter to use default value (2777)
: 2777
-------------------------------------------------------------------------------
== Web address ==
type value
: http://203.0.113.1
-------------------------------------------------------------------------------
== Data directory ==
type value, press Enter to use default value (/var/www/html/moodledata)
: /var/www/moodledata
-------------------------------------------------------------------------------
== Choose database driver ==
mysqli
mariadb
type value, press Enter to use default value (mysqli)
: mariadb
-------------------------------------------------------------------------------
== Database host ==
type value, press Enter to use default value (localhost)
: localhost
-------------------------------------------------------------------------------
== Database name ==
type value, press Enter to use default value (moodle)
: moodle
-------------------------------------------------------------------------------
== Tables prefix ==
type value, press Enter to use default value (mdl_)
: mdl_
-------------------------------------------------------------------------------
== Database port ==
type value, press Enter to use default value ()
:
-------------------------------------------------------------------------------
== Unix socket ==
type value, press Enter to use default value ()
:
-------------------------------------------------------------------------------
== Database user ==
type value, press Enter to use default value (root)
: moodleuser
-------------------------------------------------------------------------------
== Database password ==
type value
: yourpassword
-------------------------------------------------------------------------------
== Full site name ==
type value
: MY Moodle Site
-------------------------------------------------------------------------------
== Short name for site (eg single word) ==
type value
: moodle
-------------------------------------------------------------------------------
== Admin account username ==
type value, press Enter to use default value (admin)
: admin
-------------------------------------------------------------------------------
== New admin user password ==
type value
: your-admin-password
-------------------------------------------------------------------------------
== New admin user email address ==
type value, press Enter to use default value ()
: admin@example.com
-------------------------------------------------------------------------------
== Upgrade key (leave empty to not set it) ==
type value
:
-------------------------------------------------------------------------------
Have you read these conditions and understood them?
type y (means yes) or n (means no)
: y
/var/www/html/config.php
Having Moodle successfully installed, you need to allow the apache
user to read Moodle configurations by modifying the permissions to /var/www/html/config.php
as below:
sudo chmod o+r /var/www/html/moodle/config.php
Additionally, you need to setup a cron job in order to keep Moodle running correctly:
sudo crontab -u apache -e
Populate the cron file with:
* * * * * /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null
Save and quit:
:wq!
Restart Apache in order to apply all your modifications:
sudo systemctl restart httpd.service
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
Finally, point your web browser to http://203.0.113.1
to visit the Moodle website. Use the admin's username and password you setup earlier to log in.
This concludes our tutorial. Thanks for reading.
You could earn up to $300 by adding new articles