In this tutorial, we will show you how to install Moodle on Ubuntu 20.04 LTS. For those of you who didn’t know, 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.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Moodle on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
Prerequisites
- A server running one of the following operating systems: Ubuntu 20.04, 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Moodle on Ubuntu 20.04 LTS Focal Fossa
Step 1. 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
Step 2. Install the LEMP server.
A Ubuntu 20.04 LEMP server is required. If you do not have LAMP stack installed, you can follow our guide here.
Step 3. Installing Moodle on Ubuntu 20.04.
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/
We will need to change some folders permissions:
sudo chown www-data:www-data -R /var/www/html/moodle sudo chmod 775 -R /var/www/html/moodle
Next, 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
Step 4. Configuring 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;
Step 5. Configuring 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.idroot.us'; $CFG->dataroot = '/var/moodledata'; as shown.
Step 6. Configuring 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.idroot.us; 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
Step 6. Accessing Moodle Web Interface.
Moodle will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://learning.idroot.us
or https://server-ip-address
and complete the required steps to finish the installation.
Congratulations! You have successfully installed Moodle. Thanks for using this tutorial for installing Moodle Learning Management System on Ubuntu 20.04 LTS Focal Fossa. For additional help or useful information, we recommend you to check the official Moodle website.