How to Install Moodle on AlmaLinux 9

/ Category: Guide, Linux, Tutorials / Comments: None

install moodle on almalinux
Spread the love

Moodle is an open-source platform for online learning. It is a Learning Management System used by educational institutions that enable them to create online courses, training, learning and assignments. Originally, Moodle was known as an acronym for Modular Object-Oriented Dynamic Learning Environment. In this tutorial, we will show you how to install Moodle on AlmaLinux 9.


Step 1. Log in to your server via SSH

First, you will need to log in to your AlmaLinux 9 VPS via SSH as the root user:

ssh [email protected]_Address -p Port_number

You will need to replace ‘IP_Address’ and ‘Port_number’ with your server’s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the system user with sudo privileges.

You can check whether you have the proper AlmaLinux version installed on your server with the following command:

# cat /etc/almalinux-release
[[email protected] ~]# cat /etc/almalinux-release 
AlmaLinux release 9.1 (Lime Lynx)

We will use ‘root’ in this article to execute the shell commands. If you want to use your own regular user with sudo privileges to run the commands, make sure to append ‘sudo’ in front of the commands.

Step 2. Update the system

Before starting, let’s check if all AlmaLinux OS packages installed on the server are up to date. You can do this by running the following commands:

# dnf update
# dnf upgrade

We also need to install the additional packages.

# dnf install epel-release git

Step 3. Install PHP

The latest Moodle version supports PHP 8, and AlmaLinux 9 ships PHP 8.0 in the repository. To install it, let’s execute the following command.

# dnf install php-{bcmath,common,curl,fpm,gd,intl,mbstring,mysqlnd,soap,xml,xsl,zip,cli,devel,pear,json,opcache,sodium} libsodium libsodium-devel

Now that PHP 8 and its extensions are installed, we need to modify the PHP variable max_input_vars. The default value is 1000, and we need to increase it by at least 5000.

# nano /etc/php.ini

Then, append this line below.

max_input_vars = 10000

Save the file, then exit from the editor. And we can start PHP-FPM and enable it on boot.

# systemctl enable --now php-fpm

Step 4. Install and Configure Nginx

In this tutorial, we will use nginx as the web server. Let’s create an nginx server block for our Moodle website.

# nano /etc/nginx/conf.d/moodle.conf

Insert the following into the file.

   listen 80;
   root /opt/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 php-fpm;
     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 exit from the nano editor. Do not forget to start and enable nginx.

# systemctl enable --now nginx

Step 5. Install SSL/TLS Certificate

This is an optional but highly recommended step. We are going to use a free SSL/TLS certificate from Let’s Encrypt for our Moodle website.

First, we need to install it.

# dnf install python3-certbot-nginx

Now, let’s generate an SSL/TLS certificate for our Moodle website.

# cerbot --nginx

You will be prompted to choose which website we are going to install the certificate for. In the example below, we only have one nginx server block.

[[email protected] ~]# certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Requesting a certificate for

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/
Key is saved at: /etc/letsencrypt/live/
This certificate expires on 2023-05-08.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for to /etc/nginx/conf.d/moodle.conf
Congratulations! You have successfully enabled HTTPS on

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt:
* Donating to EFF:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

That’s it. An SSL/TLS certificate has been issued and enabled.

Now, you will see that certbot also update your moodle nginx server block; it also redirects HTTP to HTTPS. You can confirm this by opening /etc/nginx/conf.d/moodle.conf

Step 6. Install MariaDB Server

Moodle supports several database servers, and this time we are going to use MariaDB. Let’s run this command below to install the MariaDB server.

# dnf install mariadb-server

Once installed, we can start the service and then create a database for this Moodle installation purpose.

# systemctl enable --now mariadb

After the service is running, we can run the commands below in the MariaDB shell.

# mysql
MariaDB [(none)]> CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB [(none)]> CREATE USER 'moodle'@'localhost' IDENTIFIED BY 'm0d1fyth15';
MariaDB [(none)]> GRANT ALL ON moodle.* TO 'moodle'@'localhost';
MariaDB [(none)]> \q

Step 7. Install Moodle

In this tutorial, we are going to use Git to install Moodle. With this method, it will be easier to upgrade Moodle in the future.

Now, we are going to install Moodle in /opt/moodle and save the Moodle data in /opt/moodledata

# cd /opt
# git clone

The command above will clone Moodle from the GitHub repository to /opt/moodle and you will see an output similar to this:

[[email protected] opt]# git clone
Cloning into 'moodle'...
remote: Enumerating objects: 1346551, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 1346551 (delta 0), reused 0 (delta 0), pack-reused 1346547
Receiving objects: 100% (1346551/1346551), 646.21 MiB | 7.88 MiB/s, done.
Resolving deltas: 100% (948479/948479), done.
Updating files: 100% (25395/25395), done.

Once cloned, we can go into moodle directory then check the available Moodle branch.

# cd moodle/
# git branch -a

It will show you an output like this.

* master
remotes/origin/HEAD -> origin/master

Choose the latest stable branch, then checkout. At the time of writing this article, the last stable version is 401.

# git branch --track MOODLE_401_STABLE origin/MOODLE_401_STABLE
# git checkout MOODLE_401_STABLE

Finally, check the status using this command below.

# git status

You will see an output like this:

On branch MOODLE_401_STABLE
Your branch is up to date with 'origin/MOODLE_401_STABLE'.

nothing to commit, working tree clean

Not, it is time to change the file permission.

# mkdir -p /opt/moodledata
# chown -R apache. /opt/moodle*

Suppose you wonder why the permission is set to apache, not nginx. It is because PHP-FPM uses the user ‘apache’ by default. You can modify it to ‘nginx’. Just make sure to match the files/directories ownership with php-fpm user.

Now, it is time to go to and finish the installation instruction wizard.

Click Next to continue.

Click Next again.

In this step, we need to choose MariaDB instead of MySQL.

In this step, you need to fill them in with the database credentials we created in the previous step. You can let the database port and unix socket empty, then click on the Next button.

Click Continue

If everything is okay, click Continue to proceed. The installation will install the required Moodle modules, and it will take a few minutes to complete.

After installing the modules, click Continue to proceed to the next step.

In this step, you need to fill in the required fields before you can continue.

Make sure to fill them all, then click on the Save changes button.

You can fill them and continue or skip the registration

Finally, you will be brought to the dashboard

Step 8. Install Cron

To make Moodle run properly, we need to configure Moodle cronjobs. Without setting it up, your Moodle website might not run properly.

# crontab -u apache -e

Append this line to the file editor.

* * * * * /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null

Save the file, then exit.

That’s it! You followed this article, and now you should be able to install Moodle on AlmaLinux 9.

Of course, you don’t have to spend your time and follow this article to install Moodle on AlmaLinux 9 if you have an active AlmaLinux VPS Hosting service with us, in which case you can ask our expert Linux admins to install Moodle for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to install Moodle on AlmaLinux 9, please share it with your friends on social networks or leave a reply below. Thanks.

Be the first to write a comment.

Your feedback