Moodle is an open-source Learning Platform or Learning Management System (LMS) and it is one of the most popular LMS among educators around the world for creating a robust, secure and integrated system that can help create effective online courses as a dynamic website.
In this tutorial, we will describe how to install Moodle LMS on CentOS 7.
Prerequisites
- A CentOS 7 x64 server instance with at least 2GB of RAM (4GB or more recommended).
- A root or sudo user.
- The EPEL yum repository.
Step 1: Update the system
The first step is to update the system.
# yum update -y # reboot
Step 2: Install Apache, PHP and all required extensions.
We need to first enable the Epel and Remi repository as shown below:
# yum install epel-release # rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm # yum -y install yum-utils # yum-config-manager --enable remi-php71 [Install PHP 7.1] # yum-config-manager --enable remi-php72 [Install PHP 7.2] # yum-config-manager --enable remi-php73 [Install PHP 7.3]
Next, we will install Apache and PHP with all the required dependencies with the below command:
# yum install httpd php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysqlnd php-cli php-mcrypt php-ldap -y
Now, let us start Apache web-server and enable the service to auto-start at boot time of server:
# systemctl start httpd # systemctl status httpd # systemctl enable httpd
Step 3: Install MariaDB and create a database for Moodle
We will install MariaDB with the below command:
# yum -y install mariadb mariadb-server
Next, we will start MariaDB and enable it to start at server boot:
# systemctl start mariadb.service # systemctl enable mariadb.service
Now, secure and harden the MySQL installation using the following command.
# mysql_secure_installation
We need to set a strong root password for our MariaDB and answer Y
to all of the other questions asked ( which is self explanatory) as below.
Enter current password for root (enter for none): Just press the Enter button Set root password? [Y/n]: Y New password: your-root-password Re-enter new password: your-root-password 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
Next create a database for Moodle.
Log into the MySQL shell as root
:
# mysql -uroot -p
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;
Step 4: Download and Install Moodle
We can download the latest stable version of Moodle with the following command.
# wget https://download.moodle.org/stable37/moodle-latest-37.tgz
--2019-07-27 17:13:27-- https://download.moodle.org/stable37/moodle-latest-37.tgz Resolving download.moodle.org (download.moodle.org)... 104.20.219.25, 104.20.218.25, 2606:4700:10::6814:da19, ... Connecting to download.moodle.org (download.moodle.org)|104.20.219.25|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 45754020 (44M) [application/x-gzip] Saving to: ‘moodle-latest-37.tgz’ 100%[==============================================================================================================================>] 45,754,020 107MB/s in 0.4s 2019-07-27 17:13:28 (107 MB/s) - ‘moodle-latest-37.tgz’ saved [45754020/45754020]
# tar -zxvf moodle-latest-37.tgz # mv moodle /var/www/html # chown -R root:root /var/www/html/moodle
Next, setup a dedicated data directory for Moodle.
For security purposes, this data directory should be outside of the web root directory:
# mkdir /var/www/moodledata # chown -R apache:apache /var/www/moodledata # chmod -R 755 /var/www/moodledata
Next, we will setup a virtual host for Moodle
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 [email protected] 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
Now, its time to install Moodle from CLI
# /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://Server-IP/ or http://Domain-Name ------------------------------------------------------------------------------- == 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 () : [email protected] ------------------------------------------------------------------------------- == 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
Modify permissions to /var/www/html/config.php
Allow the apache
user to read Moodle configurations by modifying the permissions to /var/www/html/config.php
and set the cron file and insert data as below:
# chmod o+r /var/www/html/moodle/config.php # crontab -u apache -e * * * * * /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null # wq!
Step 5: Restart Apache and modify Firewall rules.
# systemctl restart httpd.service # firewall-cmd --zone=public --permanent --add-service=http # firewall-cmd --reload
Next we will browse the server IP or the domain URL to access the Moodle application as below.
http://server-ip/ or http://domain-name/
This completes the Moodle installation tutorial. Enjoy using your new LMS site!
For Pimcore installation tutorial, please visit this link