Applications Azure

Moodle 4.1 on Rocky Linux 8 on Azure User Guide

| Product: Moodle 4.1 on Rocky Linux 8 on Azure

Overview

This guide covers the deployment and operation of Moodle 4.1 on Rocky Linux 8 on Microsoft Azure, using cloudimg's virtual machine image from the Azure Marketplace (offer prod-gmheemmk2mgqo).

Moodle is the open source learning management system used by schools, universities and companies to run online courses. This image runs Moodle 4.1.22+ on Rocky Linux 8.10, served by the Apache HTTP Server with PHP FPM 8.0, with its database in MariaDB 10.11 on the same virtual machine.

⚠️ End of life status: read before deploying

Moodle 4.1 is no longer supported upstream. According to Moodle's release table (https://moodledev.io/general/releases), bug fixes for 4.1 ended on 11 December 2023 and security fixes ended on 8 December 2025; 4.1.22 is the final 4.1 release, and Moodle says the 4.1 branch "will not receive fixes for security risks". PHP 8.0 is also past the PHP project's own end of life; Remi's repository, which this image uses, still publishes PHP 8.0 package updates. This image suits sites that must stay on Moodle 4.1 for now, for example while their plugins or themes are certified for a newer release.

Plan the move to a supported release. Step 11 upgrades a machine from this image to Moodle 4.5, the long term support release that receives security fixes until 4 October 2027, together with PHP 8.3.

What's included:

  • Moodle 4.1.22+ (Build: 20251212), installed at /var/www/moodle
  • The Apache HTTP Server 2.4 with PHP FPM 8.0 (Remi's modular repository) and OPcache
  • MariaDB 10.11, listening on the loopback address only
  • A first boot service that creates the Moodle database, the database passwords and the Moodle administrator password for each virtual machine, and installs the site with Moodle's command line installer: two machines from this image never share a password
  • Moodle's scheduled tasks run every minute from cron
  • The MariaDB data directory on its own Azure data disk
  • SELinux in enforcing mode
  • cloudimg's support team on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours

Platform: Microsoft Azure (Generation 2 Hyper V) Default user: azureuser

Prerequisites

Before deploying this image, ensure you have:

  1. An active Microsoft Azure subscription, and permission to create virtual machines in a resource group
  2. The Azure CLI, installed locally or in Azure Cloud Shell
  3. An SSH key pair for Linux VM access
  4. A network security group that allows SSH (port 22) from your own network, and HTTP (port 80) from the networks your learners use

Step 1: Deploy the Virtual Machine

Deploy the image by its Marketplace URN. The image carries a purchase plan, so accept its terms once per subscription first:

az vm image terms accept --urn cloudimg1647283583153:prod-gmheemmk2mgqo:prod-gmheemmk2mgqo-gen2:latest

az vm create \
  --resource-group myResourceGroup \
  --name my-moodle-vm \
  --image cloudimg1647283583153:prod-gmheemmk2mgqo:prod-gmheemmk2mgqo-gen2:latest \
  --admin-username azureuser \
  --ssh-key-values ~/.ssh/id_rsa.pub \
  --public-ip-sku Standard

Add --size with the size your site needs. The image brings two data disks with it, at LUN 0 and LUN 1; the first boot formats and mounts them (see the filesystem table below).

Then open port 80 to your learners. This command opens it to everyone; to limit it, edit the rule in the network security group afterwards:

az vm open-port --resource-group myResourceGroup --name my-moodle-vm --port 80 --priority 1010

Step 2: Connect via SSH

Run these on your own workstation, not on the VM. Find the public IP, then connect:

az vm show --resource-group myResourceGroup --name my-moodle-vm --show-details --query publicIps -o tsv
ssh azureuser@<vm-ip>

Step 3: Wait for the first boot, and check the services

The first boot installs the Moodle site, which takes about two minutes after the machine starts, and Apache starts once it is done. Wait for Apache, then check the services:

until systemctl is-active -q httpd; do sleep 5; done
systemctl is-active cloudimg-firstboot-moodle httpd php-fpm mariadb
active
active
active
active

Apache answers on port 80, and MariaDB listens only on the virtual machine itself:

sudo ss -Htln | awk '{print $4}' | grep -E ':(80|3306)$'
127.0.0.1:3306
*:80

Step 4: Read the administrator password

The first boot writes the Moodle administrator's user name and password, the MariaDB root password and the Moodle database user's password to /root/moodle-credentials.txt, which only root can read:

sudo cat /root/moodle-credentials.txt

The file names the user admin. Keep the passwords somewhere safe, such as a password manager, and never commit them to source control.

Step 5: Set the site URL to your public address

Moodle sends every visitor to its configured site URL ($CFG->wwwroot in /var/www/moodle/config.php). On this image the first boot writes the virtual machine's private address there when the machine has a Standard public IP (Azure's default), so a browser at the public address is redirected to an address it cannot reach. Set it to the public address, which Azure's instance metadata service reports to the virtual machine itself:

PUBLIC_IP=$(curl -s -H Metadata:true 'http://169.254.169.254/metadata/loadbalancer?api-version=2020-10-01' | grep -o '"frontendIpAddress":"[^"]*"' | head -1 | cut -d'"' -f4)
PRIV=$(hostname -I | awk '{print $1}')
sudo sed -i "s|^\$CFG->wwwroot = 'http://$PRIV';|\$CFG->wwwroot = 'http://$PUBLIC_IP';|" /var/www/moodle/config.php
sudo sed -i "s|http://$PRIV|http://$PUBLIC_IP|g" /root/moodle-credentials.txt
sudo -u apache php /var/www/moodle/admin/cli/purge_caches.php
sudo grep wwwroot /var/www/moodle/config.php
$CFG->wwwroot = 'http://203.0.113.25';

The last line shows your own public IP address. To serve the site under a DNS name instead, point the name at the public IP and put http://<your-domain> (or https://<your-domain> once Step 9 is done) in $CFG->wwwroot, then purge the caches the same way.

Step 6: Sign in to Moodle

Browse to http://<vm-ip>/login/index.php. Self registration is off, so the only account is the administrator's.

Moodle 4.1 sign-in page

Sign in as admin, with the password from Step 4. Moodle opens the dashboard:

Moodle 4.1 dashboard after the first sign-in

On the first visit to Site administration, Moodle 4.1 offers to register your site with moodle.org. Registration is optional: you can skip it.

To check the Moodle release from the shell:

sudo -u apache php /var/www/moodle/admin/cli/cfg.php --name=release
4.1.22+ (Build: 20251212)

To change the administrator password, open the user menu (the AU avatar), choose Preferences, then Change password. From the shell:

sudo -u apache php /var/www/moodle/admin/cli/reset_password.php --username=admin --password='<new-password>' --ignore-password-policy

Step 7: Create your first course

Open Site administration, Courses, Manage courses and categories. Moodle starts with one category, Category 1; select Create new course, give the course a full name and a short name, and select Save and display.

Moodle 4.1 course and category management

From the course page, add sections, activities (assignments, quizzes, forums) and resources (files, pages, links), and enrol your teachers and students under Participants.

Site administration holds every site wide setting: users and authentication, courses, plugins, appearance and server settings.

Moodle 4.1 Site administration

Step 8: Outbound email

Moodle sends notifications, password resets and forum posts by email. Set an SMTP relay under Site administration, Server, Email, Outgoing mail configuration: the SMTP host and port (for example smtp.example.com:587), TLS security, and the user name and password your mail provider issued. SELinux on this image already lets Apache open outbound network connections (httpd_can_network_connect is on), so no SELinux change is needed for an SMTP relay.

Step 9: HTTPS

The image serves Moodle over plain HTTP on port 80. For a production site, put it behind HTTPS so sign-in sessions cannot be read on the network. With a DNS name pointed at the virtual machine and port 443 open in the network security group, Apache's mod_ssl and a certificate from your certificate authority (or Let's Encrypt's certbot) give the site HTTPS; then set $CFG->wwwroot to https://<your-domain> and purge the caches as in Step 5.

Step 10: Backups and system updates

Moodle keeps its data in two places that must be backed up together: the MariaDB database and the moodledata directory. Back up the code too before any upgrade:

cd ~
sudo mariadb-dump --single-transaction --default-character-set=utf8mb4 moodle | gzip > moodle-db-$(date +%F).sql.gz
sudo tar -czf moodle-data-$(date +%F).tgz -C /var moodledata
sudo tar -czf moodle-code-$(date +%F).tgz -C /var/www moodle

Copy the three files off the machine, for example to Azure Blob Storage. Azure Backup or disk snapshots of the OS disk and the MariaDB data disk are a good addition.

The image does not install updates by itself. Apply Rocky Linux's updates, including the Apache, MariaDB and PHP packages, and restart when the command below asks for it:

sudo dnf -y update
sudo dnf needs-restarting -r || sudo systemctl reboot

Everything starts again on its own after the restart, and the site URL from Step 5 is kept.

Step 11: Upgrade to Moodle 4.5

Moodle 4.5 is a long term support release with security fixes until 4 October 2027. It needs PHP 8.1 or later, so the upgrade moves PHP to 8.3 from Remi's modular repository (already enabled on this image), then replaces the Moodle code and runs Moodle's upgrade. Take the three backups from Step 10 first, and check that any extra plugins you have installed support Moodle 4.5.

sudo -u apache php /var/www/moodle/admin/cli/maintenance.php --enable
sudo dnf -y module switch-to php:remi-8.3
sudo systemctl restart php-fpm httpd
cd ~
curl -fsSLO https://download.moodle.org/download.php/direct/stable405/moodle-latest-405.tgz
sudo mv /var/www/moodle /var/www/moodle-4.1
sudo tar -xzf moodle-latest-405.tgz -C /var/www --no-same-owner
sudo cp -p /var/www/moodle-4.1/config.php /var/www/moodle/config.php
sudo restorecon -R /var/www/moodle
sudo -u apache php /var/www/moodle/admin/cli/upgrade.php --non-interactive
sudo -u apache php /var/www/moodle/admin/cli/maintenance.php --disable
sudo -u apache php /var/www/moodle/admin/cli/cfg.php --name=release

On a fresh machine from this image, the upgrade ends with:

Command line upgrade from 4.1.22+ (Build: 20251212) (2022112822.01) to 4.5.16+ (Build: 20261124) (2024100716.02) completed successfully.

The release you get is the newest 4.5 build on the day you run it. Copy any extra plugins from /var/www/moodle-4.1 into the new tree before the upgrade step, and remove /var/www/moodle-4.1 once the site is working. Later 4.5 releases install the same way. Moodle 5.3, the newest long term support release, needs MariaDB 11.4 or later, newer than this image's MariaDB 10.11; see Moodle's release notes for each version's requirements before going further.

Server components

Component Version Notes
Rocky Linux 8.10 Generation 2 Hyper V
Moodle 4.1.22+ (Build: 20251212) /var/www/moodle, data in /var/moodledata
Apache HTTP Server 2.4.37 httpd, port 80
PHP FPM 8.0.30 (Remi) php-fpm, socket /run/php-fpm/www.sock
MariaDB 10.11 mariadb, 127.0.0.1:3306

Filesystem layout

Mount Size Holds
/ 63 GB the system, Moodle's code at /var/www/moodle and its data at /var/moodledata
/boot 1 GB the boot loader and kernels
/boot/efi 100 MB the EFI system partition
/var/lib/mysql 10 GB data disk (LUN 0) the MariaDB data directory
/var/www/html 10 GB data disk (LUN 1) Apache's default document root; Moodle does not use it
/mnt Azure temporary disk scratch space only: its contents are lost when the machine is deallocated

Managing the services

sudo systemctl status httpd php-fpm mariadb
sudo systemctl restart httpd php-fpm

Moodle's scheduled tasks run every minute from /etc/cron.d/moodle.

Scripts and log files

Path What it is
/usr/local/sbin/cloudimg-firstboot-moodle the first boot script (cloudimg-firstboot-moodle.service); it runs once, then writes /var/lib/cloudimg/moodle-initialised
/usr/local/sbin/cloudimg-datadisk formats and mounts the two data disks at first boot (/etc/cloudimg/datadisk.conf)
/root/moodle-credentials.txt the per VM passwords (mode 600)
/var/log/httpd/ Apache's access and error logs
sudo journalctl -u cloudimg-firstboot-moodle the first boot's log

On startup

At the first boot, cloudimg-datadisk formats and mounts the data disks, then cloudimg-firstboot-moodle sets the MariaDB root password, creates the moodle database and its user, writes config.php and installs the site. It does not run again on later boots. There is no automatic update on boot: update the system as in Step 10.

Troubleshooting

  • The browser is sent to a 10.x.x.x address: the site URL is still the private address. Run Step 5.
  • The page does not load at all: check that port 80 is open in the network security group, and that httpd and php-fpm are active.
  • The site shows an error after a change in config.php: read /var/log/httpd/error_log, and purge the caches as in Step 5.

Security recommendations

  • Keep SSH (port 22) open only to your own network.
  • Rocky Linux's rpcbind service listens on port 111 on every interface. The network security group from the Prerequisites does not open it; if you do not use NFS, switch it off:
sudo systemctl disable --now rpcbind.service rpcbind.socket
  • Change the administrator password after the first sign-in (Step 6).
  • Serve the site over HTTPS (Step 9).
  • Update the system regularly (Step 10), and plan the upgrade to a supported Moodle release (Step 11).

Support

cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours.

For Moodle itself, see the documentation at https://docs.moodle.org/ and the community forums at https://moodle.org/.