Applications Azure

Moodle 5.3 LMS on Ubuntu 24.04 on Azure User Guide

| Product: Moodle 5.3 LMS on Ubuntu 24.04 on Azure

Overview

This image runs the official Moodle 5.3.1 release on Ubuntu 24.04 LTS, served by nginx with PHP-FPM 8.3 and OPcache. Course, user and grade data live in PostgreSQL 17 on the same virtual machine. PostgreSQL listens only on its local Unix socket, and Moodle signs in to it as the www-data operating system user (peer authentication), so there is no database password to manage. Moodle's scheduled tasks run every minute from a systemd timer.

Moodle installs itself on the first boot of every virtual machine with its own command line installer. The administrator password, the site identifier and the TLS certificate are created on your virtual machine and never shared with another one. The administrator password is written to /root/moodle-credentials.txt, readable by root only.

The site is served over HTTPS from the first boot. Its address is fixed, never taken from the request: on first boot it is your virtual machine's public IP address, as reported by Azure, and you can move it to your own DNS name with one command (sudo moodle-set-hostname lms.example.com, step 8). Port 80 redirects to HTTPS. A request for any other host name gets a short page that says how to change the address, rather than the Moodle site.

The image also ships with:

  • Self-registration, guest login and web services switched off until you turn them on
  • Moodle's bundled Guzzle, JMESPath, FPDI and AWS SDK libraries replaced with releases that fix published advisories
  • nginx, PHP-FPM, PostgreSQL and the Moodle cron job blocked from reaching the Azure instance metadata endpoint and the WireServer
  • Ubuntu's unattended security upgrades switched on

The default operating system user is the administrator account you choose when you create the virtual machine (azureuser in the examples below). Moodle's code is in /var/www/moodle and its data directory is /var/www/moodledata.

Prerequisites

  • A Microsoft Azure subscription in which you can create resource groups, virtual networks and virtual machines
  • An SSH key pair for the administrator account
  • A network security group that allows inbound TCP 22 from your own network, and TCP 80 and 443 from the networks your learners use
  • The Azure CLI (az) if you deploy from the command line

The recommended size is Standard_B2s (2 vCPUs, 4 GiB memory) for evaluation and small sites. For a few hundred active learners choose a Standard_D2s_v5 or larger.

Step 1: Deploy the Virtual Machine

Option A: the Azure Portal

  1. Sign in to the Azure Portal, open Marketplace, search for Moodle 5.3 LMS on Ubuntu 24.04 by cloudimg and select Create.
  2. On Basics choose your subscription, a resource group, a region and a name, and pick Standard_B2s or larger. Under Administrator account choose SSH public key and enter your user name and key.
  3. Under Inbound port rules allow SSH (22), HTTP (80) and HTTPS (443). Limit SSH to your own address on the Networking tab afterwards if you can.
  4. Select Review + create, then Create.

First boot finishes about two minutes after the virtual machine shows Running.

Option B: the Azure CLI

Accept the Marketplace terms once per subscription, then create the virtual machine. Replace <your-mgmt-cidr> with the network you connect from, for example 203.0.113.0/24.

az vm image terms accept --urn cloudimg1647283583153:moodle-5-3-ubuntu-24-04:default:latest

RG=moodle-rg
az group create --name $RG --location eastus
az vm create \
  --resource-group $RG \
  --name moodle-01 \
  --image cloudimg1647283583153:moodle-5-3-ubuntu-24-04:default:latest \
  --size Standard_B2s \
  --admin-username azureuser \
  --ssh-key-values ~/.ssh/id_rsa.pub \
  --public-ip-sku Standard \
  --nsg-rule NONE
az vm open-port --resource-group $RG --name moodle-01 --port 80,443 --priority 1010
az network nsg rule create --resource-group $RG --nsg-name moodle-01NSG \
  --name AllowSSHFromMgmt --priority 1000 --access Allow --protocol Tcp \
  --direction Inbound --source-address-prefixes <your-mgmt-cidr> --destination-port-ranges 22

Step 2: Connect to the Virtual Machine

Find the public IP address, then connect over SSH:

az vm show --resource-group moodle-rg --name moodle-01 --show-details --query publicIps -o tsv
ssh azureuser@<public-ip>

The message of the day shows the site address and where the credentials are:

  Moodle 5.3.1 on Ubuntu 24.04 (cloudimg)
  Site address:          https://20.127.18.179/
  Admin credentials:     sudo cat /root/moodle-credentials.txt
  Use your own DNS name: sudo moodle-set-hostname lms.example.com
  User guide:            https://www.cloudimg.co.uk/guides/moodle-5-3-on-ubuntu-24-04-azure/

Check that the services are running and that Moodle answers:

systemctl is-active nginx php8.3-fpm postgresql@17-main moodle-cron.timer
sudo -u www-data php /var/www/moodle/admin/cli/cfg.php --name=release
curl -sk -o /dev/null -w '%{http_code}\n' https://127.0.0.1/healthz
active
active
active
active
5.3.1 (Build: 20261112)
200

Moodle 5.3 services, versions and health check on a new VM

Step 3: Read the Administrator Credentials

ssh azureuser@<public-ip>
sudo cat /root/moodle-credentials.txt

The file holds the site address, the administrator user name (admin) and the administrator password created for this virtual machine:

# Moodle 5.3.1 - generated on first boot by moodle-firstboot.service. Unique to this VM; store it safely.
moodle.url=https://20.127.18.179/
MOODLE_URL=https://20.127.18.179/
moodle.admin.user=admin
moodle.admin.pass=************************

# Sign in at moodle.url as the admin user above, then change the password under Preferences > Change password.
# Database: PostgreSQL 17 on this VM, reachable only through its local Unix socket. Moodle signs in as the
# operating-system user www-data (peer authentication), so no database password exists.
# The site uses a self-signed certificate created for this VM; your browser warns until you install your own.
# Serve Moodle on your own DNS name:  sudo moodle-set-hostname lms.example.com
# User guide: https://www.cloudimg.co.uk/guides/moodle-5-3-on-ubuntu-24-04-azure/

Store the password in a password manager. If Azure did not report a public IP address when the virtual machine first booted (for example, a virtual machine with only a private address behind a firewall), the file ends with a note saying so, and the site is set up for the private address until you run moodle-set-hostname (step 8).

The per VM credentials file and its permissions

Step 4: Sign in to Moodle

Open https://<public-ip>/ in your browser. The certificate is a self-signed one made for this virtual machine, so the browser warns once; accept it to continue, or install your own certificate first (step 9). Moodle opens its sign-in page.

The Moodle 5.3 sign-in page served over HTTPS on first boot

Sign in as admin with the password from the credentials file.

Step 5: The Dashboard

After you sign in, Moodle opens your dashboard. On the first visit Moodle shows a short tour of the page; select Got it to close it. The top bar holds Dashboard and Site administration (more entries appear once you have courses), and the user menu at the top right holds your profile, preferences and Log out.

The Moodle 5.3 dashboard after the first sign in

Change the administrator password now: open the user menu, choose Preferences, then Change password. From the command line, as root, the same is:

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

Step 6: Create Your First Course

Open Site administration, then Courses, then Manage courses and categories. Moodle ships with one category, Category 1. Select it, then Create new course, and fill in the full name, the short name and the start date. Save and display opens the new course, where you add sections, activities (assignments, quizzes, forums, H5P) and resources (files, pages, links).

Course and category management in Moodle 5.3

Enrol teachers and students from the course's Participants page, or turn on self enrolment under the course's enrolment methods.

Step 7: Site Administration

Site administration holds every site wide setting: users and authentication, courses, grades, plugins, appearance, server and reports. Use the search box at the top of the page to find a setting by name. Moodle shows a reminder at the top of the page until the site is registered with moodle.org; registration is optional, and Register your site sends your site's details to Moodle so that you receive its security alerts by email.

Moodle 5.3 Site administration

The image starts with self-registration, guest login and web services off. Turn them on under Site administration when you need them: Plugins > Authentication > Manage authentication for email based self-registration and guest login, and General > Advanced features for web services.

Step 8: Serve Moodle on Your Own DNS Name

Moodle builds every link from one fixed address. On first boot that is the public IP address Azure reports for the virtual machine. To use a DNS name instead, point an A record at the public IP address, then run:

sudo moodle-set-hostname <your-domain>

The command writes the name to /etc/cloudimg/moodle-hostname, sets $CFG->wwwroot to https://<your-domain>, issues a new self-signed certificate for that name (only while the certificate is still the one cloudimg made), updates the credentials file and purges Moodle's caches. A pinned name survives reboots and public IP changes. To print the current address:

moodle-set-hostname --show
https://20.127.18.179/
(automatic: this VM's address from Azure)

sudo moodle-set-hostname --auto removes the pin and goes back to the virtual machine's own address from Azure. A browser that reaches the virtual machine at any other name or address gets a short page that names the command above instead of the Moodle site, so links and sign-in cookies always use one address.

The site address, where it came from, and the certificate made for it

Step 9: Install Your Own TLS Certificate

nginx reads the certificate from /etc/ssl/moodle/moodle.crt and the key from /etc/ssl/moodle/moodle.key. Once you replace them with your own, moodle-set-hostname leaves them alone. With a DNS name set (step 8), you can get a free Let's Encrypt certificate. Port 80 must be open to the Internet while certbot runs, and nginx is stopped for the few seconds it needs:

sudo apt-get install -y certbot
sudo certbot certonly --standalone -d <your-domain> -m <your-email> --agree-tos -n \
  --pre-hook 'systemctl stop nginx' --post-hook 'systemctl start nginx' \
  --deploy-hook 'install -m 0644 $RENEWED_LINEAGE/fullchain.pem /etc/ssl/moodle/moodle.crt; install -m 0600 $RENEWED_LINEAGE/privkey.pem /etc/ssl/moodle/moodle.key'

The deploy hook copies each renewed certificate into place, and certbot's own timer renews it before it expires.

Step 10: Configure Outgoing Email

Moodle sends notifications, password resets and forum digests by email. Azure blocks outbound port 25, so use an SMTP relay on port 587 (Azure Communication Services, SendGrid, Microsoft 365 or similar). Open Site administration > Server > Email > Outgoing mail configuration, set SMTP hosts to smtp.example.com:587, SMTP security to TLS, and enter the relay's user name and password. Set No-reply address to an address your relay may send from, save, then send a test from Site administration > Server > Email > Test outgoing mail configuration.

Step 11: Back Up and Upgrade

Back up the database and the data directory together:

sudo -u postgres pg_dump -Fc moodle > <backup-dir>/moodle-db.dump
sudo tar -czf <backup-dir>/moodledata.tgz -C /var/www moodledata

Copy both files off the virtual machine, for example to Azure Blob Storage. Azure Backup can also take scheduled snapshots of the whole virtual machine.

Ubuntu's unattended upgrades install security updates every day, PostgreSQL 17 included. To install every pending update yourself:

sudo apt-get update && sudo apt-get -y upgrade

Moodle itself is upgraded from the official release package. Take a backup first, then put the site into maintenance mode, replace the code (keep your config.php), run the upgrade and leave maintenance mode. The release notes at https://moodledev.io/general/releases say what each version changes.

sudo -u www-data php /var/www/moodle/admin/cli/maintenance.php --enable
sudo -u www-data php /var/www/moodle/admin/cli/upgrade.php --non-interactive
sudo -u www-data php /var/www/moodle/admin/cli/maintenance.php --disable

Server Components

Component Version Notes
Moodle 5.3.1 (Build: 20261112) Official release package, /var/www/moodle (web root /var/www/moodle/public)
nginx 1.24.0 HTTPS on 443, port 80 redirects to HTTPS
PHP-FPM 8.3 Ubuntu 24.04 packages, OPcache on
PostgreSQL 17 PostgreSQL Global Development Group packages, local socket only
Ubuntu 24.04 LTS Azure kernel 6.8, unattended security upgrades on

Filesystem Layout

Mount Size What is there
/ 30 GB OS disk (29 GB root partition) Ubuntu, Moodle code in /var/www/moodle, the data directory /var/www/moodledata, PostgreSQL data in /var/lib/postgresql/17/main
/boot 913 MB Kernels
/boot/efi 106 MB EFI system partition
/mnt Azure temporary disk (size depends on the VM size) Scratch space only: Azure may wipe it on a stop, resize or redeploy. Never keep Moodle data here

For a larger site, attach a managed data disk and move /var/www/moodledata and the PostgreSQL data directory onto it.

Managing the Services

sudo systemctl status nginx php8.3-fpm postgresql@17-main --no-pager
sudo systemctl restart php8.3-fpm
systemctl list-timers moodle-cron.timer --no-pager

Moodle's own command line tools live in /var/www/moodle/admin/cli and run as www-data. For example, to purge every cache:

sudo -u www-data php /var/www/moodle/admin/cli/purge_caches.php

Scripts and Log Files

Path What it does
/usr/local/sbin/moodle-firstboot.sh First boot: creates the database, installs the site, sets the administrator password and the certificate, then writes /var/lib/cloudimg/moodle-firstboot.done
/usr/local/sbin/moodle-set-hostname Shows or changes the site address (step 8)
/usr/local/sbin/moodle-detect-host Reads this virtual machine's address from Azure at boot
/root/moodle-credentials.txt The site address and administrator credentials (root only)
journalctl -u moodle-firstboot The first boot log
/var/log/nginx/ nginx access and error logs
/var/log/postgresql/ PostgreSQL logs

On Startup

On the first boot moodle-firstboot.service runs once: it reads the virtual machine's address from Azure, creates the database, installs the site with a new administrator password, makes the TLS certificate and writes the credentials file, then records /var/lib/cloudimg/moodle-firstboot.done so it never runs again. On every boot moodle-hostname.service reads the virtual machine's address from Azure again; a site that is not pinned with moodle-set-hostname follows a changed public IP address, and a pinned one keeps its name. After that nginx, PHP-FPM, PostgreSQL and the Moodle cron timer start as normal systemd services. Ubuntu's unattended upgrades run on their usual daily timer.

Troubleshooting

The browser shows "This Moodle site is served at its configured address only". You reached the virtual machine at a name or address other than the site's own. Run moodle-set-hostname --show to see the site address, or sudo moodle-set-hostname <the address you used> to move the site there.

The credentials file is not there yet. First boot is still running. Wait a minute, then check systemctl status moodle-firstboot --no-pager and journalctl -u moodle-firstboot --no-pager.

The browser warns about the certificate. The certificate is self-signed for this virtual machine. Install your own (step 9).

Pages are slow after a change of settings. Purge the caches with purge_caches.php (see Managing the Services).

Security Recommendations

  • Change the administrator password after the first sign in, and give each teacher and manager their own account.
  • Allow SSH only from your own network in the network security group.
  • Use a DNS name and a trusted certificate (steps 8 and 9) before you invite learners.
  • Leave unattended upgrades on, and apply Moodle security releases as they are published.
  • Keep self-registration and web services off unless you need them.

Support

cloudimg's support team is on hand 24 hours a day by email at 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/.