How to Install Moodle on Ubuntu 22.04
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
With an increasing trend towards online learning, learning management software is in high demand. Moodle is a free and open source Learning Management System (LMS) that is easy for both teachers and students to use. It allows administrators to create a powerful website for education and training courses. This guide explains how to download and install Moodle on Ubuntu 22.04. It also demonstrates how to configure and administer Moodle using the Moodle Dashboard.
What is Moodle?
Moodle is one of the more popular open source LMS applications. It is used to implement a portal for online educational and training courses. Moodle can be used for remote and hybrid learning, or as an adjunct resource for in-person courses. Moodle is available for most platforms, including Ubuntu and other Linux distributions.
Some of Moodle’s advantages are as follows:
- The Moodle platform is highly customizable and can provide students with a personalized education portal. The Moodle Dashboard allows administrators to manage the site and quickly add new courses and content.
- Features are implemented in a modular manner, so the site can be as simple or complex as the user wants.
- Moodle is stable and allows for enhanced security.
- Moodle’s intuitive user tools facilitate quick platform onboarding.
- Moodle maximizes the amount of on-screen content to improve concentration, reduce distraction, and enhance course retention.
- It provides educator features to help teachers manage and organize their courses and deadlines.
- Moodle includes a built-in video conferencing feature, complete with breakout rooms, chats, and a whiteboard.
- It includes analytics for both courses and individual students.
- Moodle features enhanced accessibility, including screen readers and keyboard navigation.
Before You Begin
If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode and Creating a Compute Instance guides.
Follow our Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access.
Configure a LAMP Stack, including the Apache web server, the MySQL RDBMS, and PHP. For more information on configuring a LAMP stack, consult the Linode guide on Installing a LAMP Stack on Ubuntu 22.04.
To properly use Moodle, configure a domain name for the server. For information on domain names and pointing the domain name to a Linode, see the Linode DNS Manager guide.
(Optional) A virtual host for the domain is not strictly required, but is recommended.
NoteThis guide is written for a non-root user. Commands that require elevated privileges are prefixed withsudo
. If you are not familiar with thesudo
command, see the Users and Groups guide.
Installing the Moodle Prerequisites
In addition to a fully-configured LAMP stack, Moodle requires a few extra PHP modules and other packages. To install the additional components, follow these instructions.
NoteUbuntu 22.04 supports PHP 8.1 by default. However, Moodle is not compatible with PHP 8.1, so release 7.4 must be used instead. If PHP 8.1 is already installed on the Linode, you must install PHP 7.4 and configure it as the active release of PHP. PHP 7.3 is also supported, but 7.4 is highly recommended. See the Moodle and PHP page for compatibility information.
Downgrading PHP can potentially affect other applications that use PHP. Use caution before attempting any downgrade. In some cases, it might be better to wait for Moodle to support PHP 8.1 before installing it.
Ensure the Ubuntu system packages are up to date.
sudo apt update && sudo apt upgrade
Confirm the active release of PHP. If this is 7.4, skip the steps marked “For Linode systems using PHP 8.1”. For systems running PHP 8.1, follow all instructions.
php -v
PHP 7.4.29 (cli) (built: Apr 28 2022 11:47:05) ( NTS )
(For Linode systems using PHP 8.1) Moodle requires PHP release 7.4 to function properly. If PHP 8.x is the active release, PHP 7.4 must be installed. To install PHP 7.4, add the
ondrej
repository, then useapt install
.sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt install php7.4 libapache2-mod-php7.4
(For Linode systems using PHP 8.1) Use the
update-alternatives
tool to set the active release of PHP to 7.4. Review the list of available releases and enter the number corresponding to release 7.4.sudo update-alternatives --config php
(For Linode systems using PHP 8.1) Disable the Apache module associated with PHP 8.1 and enable the module for PHP 7.4 using the following commands.
sudo a2dismod php8.1 sudo a2enmod php7.4
Install the remaining PHP 7.4 packages using
apt
. The name of each PHP component follows the patternphp7.4-component_name
.sudo apt install graphviz aspell ghostscript clamav php7.4-pspell php7.4-curl php7.4-gd php7.4-intl php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-ldap php7.4-zip php7.4-soap php7.4-mbstring git
Reload Apache to apply the changes.
sudo systemctl restart apache2
Downloading Moodle for Ubuntu 22.04
The Moodle documentation recommends cloning the application from Git. These instructions are designed for Ubuntu 22.04 users, but are very similar for Ubuntu 20.04. To download Moodle, follow these steps.
Move to the
/opt
directory, and clone the Moodle Git repository.cd /opt sudo git clone git://git.moodle.org/moodle.git
Change to the
moodle
directory.cd moodle
Determine the latest stable Moodle release from the Moodle Releases page. This page also lists the latest LTS release, along with a release roadmap. The newest stable release from Moodle is currently branch 4.0.
Use the
git branch
command to list the branches in the Moodle repository. Review the list and determine the branch matching the latest stable release. Currently, the best match isMOODLE_400_STABLE
.sudo git branch -a
remotes/origin/HEAD -> origin/master ... remotes/origin/MOODLE_39_STABLE remotes/origin/MOODLE_400_STABLE remotes/origin/master
Track and check out the appropriate branch. This example demonstrates how to check out
MOODLE_400_STABLE
.sudo git branch --track MOODLE_400_STABLE origin/MOODLE_400_STABLE sudo git checkout MOODLE_400_STABLE
Switched to branch 'MOODLE_400_STABLE' Your branch is up to date with 'origin/MOODLE_400_STABLE'.
Copy the contents of the Moodle repository to the root directory for the domain. If a virtual host has not been configured, this is
/var/www/html
. If there is a virtual host for the domain, the directory is likely/var/www/html/your_domain_name/public_html
. The instructions in this guide assume a virtual host has not been configured. Modify the permissions for themoodle
directory to grant read, write, and execute rights to all users.Note
These rights are only temporary. After installation is complete, write access should be locked down to the directory owner.sudo cp -R /opt/moodle /var/www/html/ sudo chmod -R 0777 /var/www/html/moodle
Create the
/var/moodledata
directory and change the directory owner and permissions.sudo mkdir /var/moodledata sudo chown -R www-data /var/moodledata sudo chmod -R 0777 /var/moodledata
Configuring the MySQL Server for Moodle
Log in to MySQL as the
root
user. The SQL prompt should appear.sudo mysql -u root -p
Create a database for Moodle to use. MySQL should respond with
Query OK
.CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Create a Moodle MySQL user. Grant them permissions for the database. Provide a better user name and a more secure password in place of
moodle-user
andpassword
in the following example. MySQL should reply withQuery OK
in each case.CREATE USER 'moodle-user'@'localhost' IDENTIFIED BY 'password'; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'moodle-user'@'localhost';
Exit the MySQL database.
quit
Installing the Moodle Application
Most of the Moodle configuration is done using the web interface. Moodle must know the location of the Moodle and data directories. You must also provide information about the Moodle database and database user.
Configuring Moodle Using the Web Interface
Finish setting up and configuring Moodle using the web interface. Ensure you have the information about the Moodle database user readily available. To configure Moodle, follow these steps.
Visit the Moodle web interface at
http://www.example.com/moodle
. Substitute the name of your domain in place ofexample.com
.http://example.com/moodle
Moodle first displays a page for selecting the default language. Choose the operational language for the site and select Next ».
The Moodle web interface now displays a form for entering path information. Enter
var/moodledata
for the Data directory. The other fields cannot be changed. Select Next » when the form is complete.On the next page, select the Improved MySQL database driver. Then enter Next ».
Moodle displays a form for the MySQL database settings. Enter the name of the
moodle
database user along with the account password. This is the MySQL user account created earlier in the tutorial. Leave the remaining settings the same. Select Next » to proceed.On the next page, Moodle displays the licensing agreement. Review the conditions and select Continue to proceed.
Moodle now verifies the installation. Ensure all
Server Checks
indicateOK
. If the installation is successful, Moodle displays the messageYour server environment meets all minimum requirements
at the bottom. Select Continue to move to the next step.Note
Moodle performs some additional tests and displays the results in theOther checks
section. This section presents some opportunities to improve performance and security. If HTTPS is not configured on the server, thesite not https
warning is displayed. This warning and any performance suggestions can be ignored for now. It is still possible to proceed with the installation.Moodle completes the installation process. Scroll down through the page and ensure all tasks indicate a
Success
status. Click Continue to proceed.At the next page, enter details about the Moodle administrator. Select Update profile when finished.
The following page asks for more information about the site, such as the site name. Enter the requested information, then click Save changes.
Click Register your site to complete the registration. The browser now displays the Moodle dashboard. This dashboard allows users to add content and administer the site.
Return to the system console and change permissions for the Moodle site. For better security, restrict write permission to the root user.
sudo chmod -R 0755 /var/www/html/moodle
Configuring System Paths for Moodle (Optional)
For better Moodle performance, configure some system paths using the Moodle dashboard. This step is optional, but highly recommended. It is also possible to complete this section at another time.
Visit the Moodle dashboard at
example.com/moodle
. Choose the Site Administration tab in the upper left.On the site administration page, select the Server tab.
From the Server page, select System Paths.
At the System Paths form, enter the following information.
- Path to du: Set this to
/usr/bin/du
. - Path to aspell: Set this to
/usr/bin/aspell
. - Path to dot: Set this to
/usr/bin/dot
.
Leave the remaining fields unchanged. After all changes have been made, click Save changes. Moodle confirms the new settings. The completed form should resemble the following example.
- Path to du: Set this to
Setting up a SSL Certificate for Moodle (Optional)
Although Moodle does not require the Hypertext Transfer Protocol Secure (HTTPS) protocol, it is highly recommended. HTTPS encrypts information using Secure Sockets Layer (SSL) technology, resulting in better security. Failure to configure HTTPS can expose the site data to various cyber attacks.
Before the Linode can accept HTTPS requests, it must possess a signed public-key certificate from a trusted certificate authority. Certbot is used to install and renew SSL certificates for the Apache web server. Certbot is a free and open source tool that automates the process of requesting Let’s Encrypt certificates for a website.
To install a SSL certificate for Moodle and the domain, follow these steps.
Update the Snap application, which is used to download application bundles. Snap comes pre-installed on Ubuntu 22.04.
sudo snap install core && sudo snap refresh core
Remove the default Ubuntu Certbot installation.
sudo apt remove certbot
Use
snap
to install Certbot.sudo snap install --classic certbot
certbot 1.27.0 from Certbot Project (certbot-eff✓) installed
Download a certificate for the domain using
certbot
.sudo certbot --apache
Certbot guides users through the installation process. The following information is required:
- A contact email for the domain owner.
- An acknowledgment of the terms of service. Enter
Y
to proceed. - Whether to share the email address with the Electronic Frontier Foundation.
- The domain name to be registered. Enter the domain both with and without the
www
prefix.
After granting the certificate, Certbot displays some information about the granting process and the certificate.
Congratulations! You have successfully enabled HTTPS on https://example.com and https://www.example.com
Certbot automatically schedules a renewal and update for the certificate. To test out the renewal procedure, launch a dry run using the
renew
command.sudo certbot renew --dry-run
Edit the Moodle configuration file at
/var/www/html/moodle/config.php
. Change the value of$CFG->wwwroot
to use thehttps
variant of the domain name. For the following command, replaceexample.com
with the actual domain name. This automatically redirects HTTP traffic to HTTPS.- File: /var/www/html/moodle/config.php
1 2 3
... $CFG->wwwroot = 'https://example.com/moodle'; ...
Restart the Apache server.
sudo systemctl restart apache2
Reload the Moodle dashboard. The URL should now resolve to the HTTPS version of the page.
How to Use Moodle
Before proceeding, spend some time exploring the Moodle Dashboard to become more aware of the different configuration options. Read through the Moodle Administration Guide to find out how to customize the site, add users, and configure course information. The Moodle Teacher Quick Guide demonstrates how to add and manage a course. More detailed information, including troubleshooting information, can be found in the Moodle Documentation library.
A Summary of How to Install Moodle on Ubuntu 22.04
Moodle is a powerful and flexible online learning management system. Moodle is a free and open source application that is available for Ubuntu 22.04 and other operating systems. Administrators can manage and configure the application using the Moodle dashboard.
Moodle is installed using Git and is configurable using a web-based interface. Moodle requires PHP release 7.4, which might require a downgrade for some systems. For more information on Moodle, see the Moodle website.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on