How to Install Moodle Learning Platform in Ubuntu 20.04

Moodle is the world’s most popular, robust, free, and open-source online learning (e-learning) management platform built for web and mobile. It offers a wide range of activities and educational tools that enable schools, universities, and related institutions to offer students a flexible learning platform any time, anywhere, without interruption to their course and curriculum.

Some of its general features include a modern, easy-to-use interface, personalized dashboard, collaborative tools and activities, all-in-one calendar, convenient file management, simple intuitive text editor, notifications, and track progress.

Importantly, Moodle is also highly extensible using over a thousand plugins that support extra activities, blocks, themes, and so much more.

In this article, you will learn how to install the latest version of the Moodle Learning Platform with NGINX and MySQL/MariaDB database on Ubuntu 20.04 and older versions.

Server Requirements:

Once you have installed the LEMP stack on the Ubuntu server, you can proceed further to set up Moodle on the server as explained below.

Setting Up DNS Record for Moodle Application

1. For users to access your Moodle instance you need to create a subdomain for it, thus, you need to create a DNS A record to achieve this. For this guide, our test domain is, so we need to create a subdomain, for example,

So, log into your domain registrar’s web console and access your domain’s advanced settings, click Add New Record of type A, a host should be learning (or any word of your choice), and value should be the public IP address of your Ubuntu server.

Create DNS A Record for Moodle Application
Create DNS A Record for Moodle Application

Installing Moodle in Ubuntu Server

2. Next, you need to install PHP extensions and libraries required by Moodle using the apt package manager as shown.

$ sudo apt update
$ sudo apt install php-common php-iconv php-curl php-mbstring php-xmlrpc php-soap php-zip php-gd php-xml php-intl php-json libpcre3 libpcre3-dev graphviz aspell ghostscript clamav

3. Next, create a database for your Moodle system. Log in to the MySQL database administration shell and create the database as shown:

$ sudo mysql

MariaDB [(none)]> CREATE DATABASE moodle;
MariaDB [(none)]> quit;

4. As mentioned earlier, for this guide, we will download and install the latest version Moodle (version 3.9 at the time of writing). Run the following wget command to grab the Moodle package and use the tar command to extract it respectively. Then use the ls command to confirm that the moodle directory exists under /var/www/html/ as shown.

$ wget -c
$ sudo tar -zvxf moodle-latest-39.tgz -C /var/www/html/
$ ls /var/www/html/

5. Next, set appropriate permissions on the Moodle directory by running the following commands.

$ sudo chown www-data:www-data -R /var/www/html/moodle
$ sudo chmod 775 -R /var/www/html/moodle

6. Next, create the Moodle data directory, a place where Moodle can save uploaded files and set its permissions as shown.

$ sudo mkdir -p /var/moodledata
$ sudo chmod 775 -R /var/moodledata
$ sudo chown www-data:www-data -R  /var/moodledata

7. Then create the Moodle main configuration file from the sample configuration file provided with the package, open it.

$ cd /var/www/html/moodle/
$ sudo cp config-dist.php config.php
$ sudo vim config.php

Lok for the database configuration section, then configure the database where all Moodle data will be stored, as shown in the following screenshot:

$CFG->dbtype    = 'mariadb';      // 'pgsql', 'mariadb', 'mysqli', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native';     // 'native' only at the moment
$CFG->dbhost    = 'localhost';  // eg 'localhost' or '' 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
Configure Moodle Database Settings
Configure Moodle Database Settings

Also, configure the Moodle website location as well as the location of the Moodle data directory as shown.

$CFG->wwwroot   = '';
$CFG->dataroot  = '/var/moodledata';
Configure Moodle Website
Configure Moodle Website

Save the close the file. Then configure NGINX to server your Moodle site as described in the next section.

Configuring NGINX to Serve Moodle Application

8. For NGINX to server your Moodle site, you need to create a new server block configuration under the NGINX configuration, in the directory /etc/nginx/conf.d/.

$ sudo vim /etc/nginx/conf.d/moodle.conf

Copy and paste the following configuration in it, replace with your subdomain. Beside, the fastcgi_pass directive should point to the address on which PHP-FPM is accepting FastCGI requests (check the /etc/php/7.4/fpm/pool.d/www.conf file for more information).

   listen 80;
    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;

Save the file and close it.

9. Next, verify that the NGINX configuration is OK after making the above changes, then gracefully restart the NGINX service.

$ sudo nginx -t
$ sudo systemctl reload nginx
Check Nginx Configuration
Check Nginx Configuration

Completing Moodle Installation via Web Installer

10. Now open a web browser and navigate using your subdomain, for example, to access the Moodle web installer.

Once the welcome page loads read through the message the click Continue.

Moodle Web Installer
Moodle Web Installer

11. Next, the installer will check whether your system meets the requirements, if everything is OK, scroll down and click Continue to start the actual installation of files and setting up database schema.

Note that the installer will show a warning about the site not running on HTTPS, ignore the warning for now. In the last section, we will cover how to enable HTTPS on Moodle using free Let’s Encrypt certificates.

Moodle System Requirements Check
Moodle System Requirements Check

Once the installation is complete, click on Continue.

Moodle Web Installation Complete
Moodle Web Installation Complete

12. Next, configure your Moodle site’s administrator account by creating the account username, password, first name and surname, and email address. Then scroll down and click Update Account.

Create Moodle Admin Account
Create a Moodle Admin Account

13. Next, configure the Moodle site front page settings as shown in the following screenshot. Then scroll down and click Update.

Configure Moodle Front Page
Configure Moodle Front Page

14. The web installer will automatically log you into the new Moodle site. You can complete your site registration by following the instructions on the screen.

Moodle Site Registration
Moodle Site Registration

Setting Up HTTPS on Moodle Application Using Let’s Encrypt

15. To protect your Moodle site, you need to enable HTTPS. For this guide, we will use Let’s Encrypt free and trusted SSL/TLS certificates. Another advantage of using Let’s Encrypt is that it is automated.

So, go back to your terminal and run the following command to install the certbot on Ubuntu (a free, open-source tool for automatically using Let’s Encrypt certificates to enable HTTPS on manually-administrated sites).

$ sudo snap install --classic certbot
Install Certbot on Ubuntu
Install Certbot on Ubuntu

16. Then issue the following command to get a certificate and have Certbot edit your NGINX configuration to automatically configure the new certificate.

$ sudo certbot --nginx
Install SSL Certificate on Moodle
Install SSL Certificate on Moodle

17. Next, go back to the Moodle site configuration file.

$ sudo vim /var/www/html/moodle/config.php 

and change the URL from HTTP to HTTPS as shown in the following screenshot.

$CFG->wwwroot   = '';
Set HTTPS on Moodle Configuration
Set HTTPS on Moodle Configuration

18. Finally, verify from the browser that your Moodle site is now running on HTTPS.
Verify HTTPS on Moodle
Verify HTTPS on Moodle

That’s all for now! Go to the Moodle 3.9 documentation for more information, configuration options, and usage guide.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.


Leave a Reply
  1. Hi, I installed the model successfully. Then I uploaded a new photo from the Edit settings section and the Frontpage summary section. (As in the photo below)

    But when I open the home page of my model site, the uploaded image is not displayed.

    I want to display a custom photo on the model home screen for users. How can I fix this problem?

    • @Janardan

      NGINX will return a 502 Bad Gateway error if it can’t successfully proxy a request to PHP-FPM, via:

      fastcgi_pass           unix:/run/php/php7.4-fpm.sock;

      Ensure that PHP-FPM is running.

  2. Using Ubuntu. I have followed all the instructions, but I keep getting this:

    “Moodle requires the iconv PHP extension. Please install or enable the iconv extension.”

    When I try to install php-iconv, I get this:

    # apt install php-iconv
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Note, selecting 'php7.4-common' instead of 'php-iconv'
    php7.4-common is already the newest version (7.4.3-4ubuntu2.4).
    0 upgraded, 0 newly installed, 0 to remove and 26 not upgraded.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.