Moodle is one of the best learning management systems available. It’s an open software, released under the open source ‘GNU General Public License’ which makes it highly flexible and customizable. In this guide you will learn how to install Moodle on Ubuntu server 20.04/22.04.
We are installing Moodle on a brand new, clean Ubuntu server with no software or data on it. If your server has data on it - make data backup first. Author is not responsible for possible data loss.
Abans de començar
Consulteu el nostre hosting service for Moodle edició comunitària. Podeu començar a utilitzar el LMS sense necessitat d'instal·lar-lo!
Requisits previs
- Instal·leu a Servidor VPS amb Ubuntu 22.04
- Aconsegueix una persona plenament qualificada nom de domini pointing to your server’s IP address, such as “moodle.example.org”
Com a exemples en aquesta guia farem servir domini moodle.example.org, canvieu-lo pel vostre propi nom de domini.
Preparing Ubuntu server for Moodle Installation
Actualitzar el sistema
Primer de tot: actualitzar el sistema. Per començar connecteu-vos al vostre servidor mitjançant SSH. A continuació, executeu les ordres "apt update" i "apt upgrade" per actualitzar els paquets del sistema a la darrera versió.
$ sudo apt update && apt upgrade -y

Instal·leu Apache, PHP-8.1, MariaDB MySQL server
Next install Moodle dependencies. We need to install Apache web server, PHP 8.1, MariaDB SQL server, mail server and a list of PHP extensions required by Moodle.
$ sudo apt install apache2 php8.1 mariadb-server postfix $ sudo apt install php8.1-mysql php8.1-fpm php8.1-iconv php8.1-mbstring php8.1-curl php8.1-tokenizer php8.1-xmlrpc php8.1-soap php8.1-ctype php8.1-zip php8.1-gd php8.1-simplexml php8.1-xml php8.1-intl
Quan finalitzi la instal·lació, inicieu el servidor web Apache.
$ sudo systemctl start apache2 $ sudo systemctl enable apache2
Configureu Apache VirtualHost i PHP-FPM
We will be running Moodle 4.2 on Apache and PHP-FPM. On the next step we will configure PHP-FPM for Apache.
1. Inicieu el servei PHP-FPM i activeu-lo a l'arrencada.
$ sudo systemctl start php8.1-fpm $ sudo systemctl enable php8.1-fpm
2. Per utilitzar PHP-FPM amb Apache hem d'habilitar els mòduls proxy_fcgi i proxy.
sudo a2enmod proxy_fcgi proxy
3. Create Apache configuration file for Moodle.
$ sudo nano /etc/apache2/sites-available/moodle.conf
Enter the following configuration into the moodle.conf. Replace ServerName, DocumentRoot, Directori amb els teus valors.
<VirtualHost *:80>
ServerName moodle.example.org
ServerAlias www.moodle.example.org
DocumentRoot /home/moodle/public_html
<Directory /home/moodle/public_html>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost/"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Deseu i tanqueu el fitxer amb CTRL X, després Y i després Enter.
4. Habiliteu el nou amfitrió virtual i torneu a carregar el servidor web Apache.
$ a2ensite moodle $ systemctl reload apache2
5. També és bo tenir una reescriptura i els mòduls SSL activats
# a2enmod rewrite # a2enmod ssl # systemctl restart apache2
Crea una base de dades i un usuari de la base de dades
1. Inicieu i activeu el servidor MariaDB SQL
root@moodle-lms-install:~# systemctl start mariadb root@moodle-lms-install:~# systemctl enable mariadb
2. Creeu usuari i base de dades MySQL
root@moodle-lms-install:~# mysql MariaDB [(none)]> create database moodle_dev; MariaDB [(none)]> grant all privileges on moodle_dev.* to moodle_user@localhost identified by 'Change_to_Strong_SQL_Password'; MariaDB [(none)]> flush privileges;
Once we have Apache, PHP and MySQL configured we can proceed with installing moodle code.
Install Moodle Code
1. Create a home directory for Moodle site and public directory
$ useradd --create-home -s /bin/sh moodle $ mkdir -p /home/moodle/public_html $ chmod 711 /home/moodle
2. Download the latest Moodle code and extract it into the public directory.
You can download latest moodle from https://download.moodle.org/releases/latest/. Get the code and upload it into the public directory. In our case the directory is “/home/moodle/public_html”
Executeu la instal·lació al navegador
Before you proceed to this final step you need to point your domain name to the IP address of your server. When DNS is configured your can run Moodle installation in a browser.
1. Open your browser and navigate to your Moodle’s site domain/sub-domain. You should see Moodle Installation page.
2. Trieu l'idioma del lloc web. Mantendrem l'anglès.

3. Confirmeu camins
On the next step confirm that web address, moodle directory and data directory are correct. Data directory was missing in our installation, so we created it on this step.
# mkdir /home/moodle/moodledata # chown www-data:www-data /home/moodle/moodledata

4. Trieu un servidor de bases de dades
Utilitzem MariaDB per a aquesta guia. Seleccioneu MariaDB al menú desplegable.

5. Introduïu la configuració de la base de dades
Introduïu el nom de la base de dades, l'usuari de la base de dades i la contrasenya que hem creat anteriorment.

6. Creeu el fitxer config.php
After entering database settings and clicking “Next” a config.php file will be generated. Copy content of the file and create “config.php” in the root moodle directory (/home/moodle/public_html in this example).
7. Acceptar la llicència
You have to read and accept Moodle license agreement on this step.
8. Passar les comprovacions del servidor
La majoria de les comprovacions van passar a la nostra instal·lació. Només hem hagut de canviar "max_input_vars" del seu valor predeterminat a 5000.
$ nano /etc/php/8.1/fpm/php.ini $ systemctl reload php8.1-fpm

9. Configura el teu compte d'administrador principal
En aquest pas, hauríeu de configurar el compte d'administrador. Introduïu el nom d'usuari, la contrasenya i altres detalls necessaris.
10. Introduïu la configuració d'inici del lloc
Configureu el nom del lloc, el nom curt del lloc, el resum de la pàgina d'inici del lloc i altra informació.

Crea el teu primer plat!
After few final clicks you will see the LMS dashboard and Calendar. Proceed to “My Courses” tab and create your first Moodle course! Well done!






