How to Install Moodle on Ubuntu 20.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.
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. The Moodle platform is highly customizable and takes a modular approach to features, so it is extensible and adaptable to your needs. This guide shows you how to get a Moodle website up and running on an Ubuntu 20.04 server.
Before You Begin
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.
Install and configure a LAMP (Linux, Apache, MySQL, and PHP) stack. Follow the How to Install a LAMP Stack on Ubuntu 20.04 guide for instructions.
For this guide, you do not need to configure a virtual host for Apache. However, you should follow all other non-optional sections in the guide linked above.
NoteThis guide is written for non-root users. Commands that require elevated privileges are prefixed with
sudo. If you are not familiar with the
sudocommand, see the Linux Users and Groups guide.
Install the Prerequisites
Install the prerequisites for Moodle. This includes software and PHP modules that support Moodle’s features and Git for installing Moodle and keeping it up to date.
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
Restart Apache to load the modules.
sudo systemctl restart apache2
Change into the
/optdirectory, clone the Moodle Git repository and change into the resulting
cd /opt sudo git clone git://git.moodle.org/moodle.git cd moodle
Determine the latest stable Moodle release from Moodle’s official list of releases. At the time of writing, the latest stable release is 3.10.
The following command lists the branches in the Git repository. From that list, identify the branch associated with the latest stable release. For release 3.10, this is
sudo git branch -a
Track and then check out the branch you identified.
sudo git branch --track MOODLE_310_STABLE origin/MOODLE_310_STABLE sudo git checkout MOODLE_310_STABLE
Copy the directory with the Moodle repository into the
/var/www/htmldirectory. Then, modify the new Moodle directory’s permissions to grant read, execute, and write access to any user.
sudo cp -R /opt/moodle /var/www/html/ sudo chmod -R 0777 /var/www/html/moodle
NoteWrite access to this directory is only meant to be granted temporarily. Once the Moodle installation is completed in the steps below, the permissions are modified to restrict write access to the directory owner (the
www-dataits owner, and modify its permissions to grant all users read, execute, and write access.
sudo mkdir /var/moodledata sudo chown -R www-data /var/moodledata sudo chmod -R 0777 /var/moodledata
Set Up the MySQL Server
Open the MySQL interface as the root user.
sudo mysql -u root -p
Use the following MySQL command to create a database for Moodle.
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Create a Moodle MySQL user, and give it the required permissions on the Moodle database. In the following example, replace
passwordwith the username and password, respectively, you would like to use for the Moodle MySQL user.
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 interface using the
Complete the Moodle Installation
In a web browser, navigate to the Moodle URL, which is your server’s domain name followed by
/moodle. So, if your server’s domain name is
example.com, then the Moodle URL would be
Follow the prompts to complete the Moodle setup. Enter the default options or your preferences for all settings except the following:
/var/moodledatafor Data directory when prompted to confirm paths.
Choose the Improved MySQL option when prompted to select a database driver.
Follow the example in the image below when you are asked to enter database settings. Replace
passwordwith the username and password, respectively, that you used when creating the Moodle MySQL user above:
Review the release information, ensure that no issues are indicated, and continue. Allow the next page to load fully — it may take some time — and ensure that all of the components listed indicate “Success”. Then, continue.
Complete the form for creating a Moodle site administrator and, on the next page, complete the form with information about your Moodle site.
Return to your server’s command line, and modify the Moodle directory’s permissions to prevent writing except by the directory owner (the root user):
sudo chmod -R 0755 /var/www/html/moodle
Configure the Moodle’s System Paths
Configuring the system paths for Moodle, while optional, enhances your Moodle site’s performance. The configuration can be done from the Moodle administration interface, using the following steps:
Navigate again to your Moodle website (
example.com/moodle) and select Site Administration from the left menu.
Click the Server tab and select System paths.
On the form presented, complete the fields as follows:
Path to du, enter
Path to aspell, enter
Path to dot, enter
Click the Save changes button.
Set Up an SSL Certificate
Update the Snap app store. Snap provides application bundles that work across major Linux distributions and is installed by default with all Ubuntu releases since 16.04.
sudo snap install core && sudo snap refresh core
Remove any existing Certbot installation.
sudo apt remove certbot
sudo snap install --classic certbot
Download a certificate for your site.
sudo certbot --apache
Certbot prompts you to enter your site’s domain name. Do so to complete the installation of the SSL certificate.
Certbot includes a chron job that automatically renews your certificate before it expires. You can test the automatic renewal with the following command:
sudo certbot renew --dry-run
Using your preferred text editor, open the Moodle configuration file,
/var/www/html/moodle/config.php. Change the
$CFG->wwwrootvalue to use
example.comin the following example with your site’s domain name.
$CFG->wwwroot = 'https://example.com/moodle';
Restart the Apache server.
sudo systemctl restart apache2
You are now ready to start using Moodle. To get started, take a look at Moodle’s Admin quick guide, which shows you how to start customizing the look of your site and how to add users and courses. Then, review the Teacher quick guide for a walkthrough on how you can manage a course. From there, check out the rest of Moodle’s documentation library for guides on the many ways you can customize your site and for instructions on getting the most out of it.
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