Moodle is an Open Source Course Management System (CMS), also known as a Learning Management System (LMS) or a Virtual Learning Environment (VLE). It has become very popular among educators around the world as a tool for creating online dynamic websites for their students.
Moodle brings features to include assignment submission, online quizzes, wiki, grading, instant messages, discussion boards, and others. But since it's modular software, it can be extended via plugins to add extra functionality.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Open-source Software Installation queries.
In this context, we shall look into how to install Moodle on Ubuntu 20.04 LTS.
1. Perform system update
First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal:
$ sudo apt update
$ sudo apt upgrade
2. Install LEMP server
A Ubuntu 20.04 LEMP server is required. If you do not have LEMP stack installed, you can follow our guide here.
3. Install Moodle on your system
Use the commands below to download the latest version of Moodle:
$ wget -c https://download.moodle.org/download.php/direct/stable39/moodle-latest-39.tgz
$ sudo tar -zvxf moodle-latest-39.tgz -C /var/www/html/
$ ls /var/www/html/
Next, We will need to change some folders permissions with the below commands:
$ sudo chown www-data:www-data -R /var/www/html/moodle
$ sudo chmod 775 -R /var/www/html/moodle
Finally, create the Moodle data directory, a place where Moodle can save uploaded files and set its permissions:
$ sudo mkdir -p /var/moodledata
$ sudo chmod 775 -R /var/moodledata
$ sudo chown www-data:www-data -R /var/moodledata
4. Configure MariaDB for Moodle
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
$ mysql_secure_installation
Configure it like this:
- Set root password? [Y/n] y
- 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, we will need to log in to the MariaDB console and create a database for Moodle. Run the following command:
$ mysql -u root -p
This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for Moodle installation:
MariaDB [(none)]> CREATE DATABASE moodle;
MariaDB [(none)]> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'moodleadmin'@'localhost' IDENTIFIED BY 'your-strong-passwd';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit;
5. Configure Moodle
Now we create the Moodle main configuration file from the sample configuration file provided with the package:
$ cd /var/www/html/moodle/
$ sudo cp config-dist.php config.php
$ sudo nano config.php
Look for the database configuration section, then configure the database where all Moodle data will be stored:
$CFG->dbtype = 'mariadb'; // 'pgsql', 'mariadb', 'mysqli', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native'; // 'native' only at the moment
$CFG->dbhost = 'localhost'; // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname = 'moodle'; // database name, eg moodle
$CFG->dbuser = 'moodleadmin'; // your database username
$CFG->dbpass = 'Secur3P@zzwd'; // your database password
$CFG->prefix = 'mdl_'; // prefix to use for all table names
Also, configure the Moodle website location as well as the location of the Moodle data directory:
$CFG->wwwroot = 'http://learning.linuxapt.com';
$CFG->dataroot = '/var/moodledata'; as shown.
6. Configure Nginx Web server
Now we create a new virtual host directive in Nginx, Go to the directory /etc/nginx/conf.d/:
$ sudo nano /etc/nginx/conf.d/moodle.conf
server{
listen 80;
server_name learning.linuxapt.com;
root /var/www/html/moodle;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^(.+\.php)(.*)$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
include /etc/nginx/mime.types;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Now, we can restart the Nginx web server so that the changes take place:
$ nginx-t
$ sudo systemctl restart nginx
7. Access Moodle Web Interface
Moodle will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://learning.linuxapt.com or https://server-ip-address and complete the required steps to finish the installation.
This article covers the best method to install Moodle Learning Management System on Ubuntu 20.04 LTS Focal Fossa. In fact, Moodle is a popular, free, and open-source Learning Management System (LMS). With Moodle, you can create a fully-featured website for education and training courses, suitable for fully online, hybrid, and in-person classroom experiences.
For additional help or useful information, we recommend you to check the official Moodle website.