This guide covers keeping a running CloudSOE Moodle instance patched and up to date. It covers PHP, the Debian 12 operating system and Moodle itself, plus moving to a fresh image for the upgrades that shouldn’t be done in place.

It’s especially important right now. PHP2Shell (CVE-2026-109618 and CVE-2026-109619) is a critical remote code execution flaw in PHP that attackers are already exploiting, and it’s one of several recent CVEs in the web stack. Moodle sites hold student data and are a popular target, so patch PHP today.

What you can upgrade in place

ComponentIn place?How
Operating system (Debian 12)Yes, for updates within Debian 12apt (see Update the operating system). For Debian 13, use a fresh image
PHP 8.4 (Sury repository)Yesapt, then restart Apache (see Patch PHP)
Moodle 5.2.x (minor releases in the 5.2 branch)YesThe Moodle CLI upgrade
Moodle major release (5.2 → newer)Use a fresh imageSee Move to a fresh CloudSOE image
Apache, MariaDB and phpMyAdminYes, for updates within Debian 12apt, along with the rest of the OS

Before you start: back up

Take both kinds of backup before you patch or upgrade anything.

1. A cloud disk snapshot. This lets you roll the whole instance back in minutes:

  • AWS: open EC2 → Volumes, select the instance’s root volume, then choose Actions → Create snapshot.
  • Azure: open the VM, go to Disks, select the OS disk, then choose Create snapshot.

2. An application-level backup. A Moodle site is its database, its data directory and its config.php:

sudo mysqldump --single-transaction moodle | gzip > /home/$(whoami)/moodle-db-$(date +%F).sql.gz
sudo tar czf /home/$(whoami)/moodledata-$(date +%F).tar.gz -C / var/moodledata
sudo cp /var/www/moodle/config.php /home/$(whoami)/config.php.bak

Copy these files off the instance, for example with scp to your own machine or to S3 or Azure Blob storage. For a consistent backup of a busy site, enable maintenance mode first.

Patch PHP (PHP2Shell)

PHP2Shell is a pair of vulnerabilities, CVE-2026-109618 and CVE-2026-109619, published on 21 October 2026. They allow critical remote code execution in PHP 5.4 through 8.5 and are being exploited in the wild. Updating PHP is the only complete fix. The published workarounds are incomplete, so don’t rely on them.

Upstream PHP fixed it in 8.2.35, 8.3.36, 8.4.27 and 8.5.12.

Where PHP comes from on this image

Moodle 5.2 needs PHP 8.3 or 8.4, but Debian 12 only ships PHP 8.2. So the CloudSOE Moodle image installs PHP 8.4 from the Sury repository (packages.sury.org), which is already configured on your instance. Sury packages follow the upstream version numbers, so php -v shows whether you’re patched.

phpMyAdmin also pulls in Sury’s php8.5-cli and php8.5-common packages. Moodle and the website don’t use them, but they get patched in the same apt run.

Check your PHP version

php -v
dpkg -l | grep -E '^ii +php[0-9.]+-(cli|common) '

Compare the version column with the fixed releases:

Base OSPHP package (source)Patched version (or later)
Debian 12php8.4 (Sury), used by Moodle8.4.27, e.g. 8.4.27-1+0~20261021.57+debian12~1
Debian 12php8.5 (Sury), pulled in by phpMyAdmin8.5.12, e.g. 8.5.12-1+0~20261021.27+debian12~1

Sury rebuilds packages regularly, so the part after the upstream number (-1+0~…) changes. Any php8.4 package of 8.4.27 or later is fixed.

Update PHP

sudo apt update
sudo apt upgrade

The Moodle image runs PHP inside Apache with libapache2-mod-php8.4, so restart Apache to load the patched PHP:

sudo systemctl restart apache2

To confirm which PHP integration Apache uses, run ls /etc/apache2/mods-enabled/ | grep php. You should see php8.4.load. Moodle’s cron job runs the PHP command line (/usr/bin/php) every minute, so it picks up the fix on its next run.

Confirm the fix

php -v                     # should say PHP 8.4.27 or later
dpkg -l | grep -E '^ii +php[0-9.]+-(cli|common) '

If php -v reports 8.5 instead of 8.4, the php command has been switched away from 8.4. Moodle 5.2 doesn’t support PHP 8.5, so point it back:

sudo update-alternatives --set php /usr/bin/php8.4

If the versions haven’t changed, run apt policy php8.4-common to check that packages.sury.org is reachable from the instance.

Update the operating system

The Moodle image runs on Debian 12 (bookworm). Security updates come from Debian’s repositories, and PHP updates come from the Sury repository:

sudo apt update
sudo apt upgrade

If apt upgrade reports packages as “kept back”, run sudo apt full-upgrade. Review the list before you confirm.

Reboot after kernel updates

Debian doesn’t always create /var/run/reboot-required, so check both:

[ -f /var/run/reboot-required ] && echo "reboot required"
uname -r                                          # running kernel
linux-version list | linux-version sort | tail -1 # newest installed kernel

If the newest installed kernel differs from the running one, reboot at a quiet time. Apache, MariaDB and Moodle’s cron start automatically:

sudo reboot

After the reboot, clear out the old kernels with sudo apt autoremove --purge.

Automatic security updates

CloudSOE images don’t change the base OS’s automatic-update settings. To see whether unattended-upgrades is active on your instance:

systemctl status unattended-upgrades
apt-config dump APT::Periodic::Unattended-Upgrade

Even if it’s on, Debian’s default configuration only installs packages from Debian’s own repositories. PHP updates from the Sury repository are not installed automatically, so patch PHP by hand as shown above whenever a PHP security release comes out.

Debian 13 and later

Don’t upgrade the release in place (Debian 12 → 13). A release upgrade changes MariaDB, Apache and the PHP repository all at once, and that’s hard to roll back on a production LMS. When you want a newer Debian release, move to a fresh CloudSOE image instead.

Upgrade Moodle

The image installs Moodle from the official release archive at packaging.moodle.org, not from a Debian package or git. The code lives in /var/www/moodle and is read-only to the web server: the directory is owned by root, and only config.php belongs to www-data. Moodle’s data lives in /var/moodledata, owned by www-data. Apache serves only /var/www/moodle/public.

A Moodle upgrade means replacing the code with the new release, keeping config.php and your add-on plugins, then running the CLI upgrade.

Which upgrades to do in place

  • Minor releases in the 5.2 branch (5.2.1, 5.2.2 and so on) carry security and bug fixes. Apply them in place, as shown below. Site administration → Notifications tells you when one is available.
  • A new major release has its own PHP, database and minimum-upgrade-from requirements, which you’ll find in the Moodle release notes. Moodle’s upgrade refuses to run if the environment doesn’t meet them. For a major jump, move to a fresh CloudSOE image built for that release instead. That gets you a matching PHP version without changing repositories on a live server.
  • Moodle only moves forward. You can’t downgrade, which is why the backup comes first.

Step by step (5.2.x minor upgrade)

  1. Find your add-on plugins. In Moodle, open Site administration → Plugins → Plugins overview and choose Additional plugins. Note where each one lives. Plugins live under /var/www/moodle/public/, e.g. public/mod/<name> or public/theme/<name>.

  2. Turn on maintenance mode, then download the latest 5.2 release.

sudo -u www-data /usr/bin/php /var/www/moodle/admin/cli/maintenance.php --enable

cd /tmp
curl -fLO https://packaging.moodle.org/stable502/moodle-latest-502.tgz
  1. Swap in the new code, keeping the old tree for rollback:
sudo mv /var/www/moodle /var/www/moodle.old
sudo tar xzf /tmp/moodle-latest-502.tgz -C /var/www --no-same-owner
sudo cp -p /var/www/moodle.old/config.php /var/www/moodle/config.php
sudo chown root:root /var/www/moodle
sudo chown www-data:www-data /var/www/moodle/config.php
sudo chmod 640 /var/www/moodle/config.php
  1. Copy your add-on plugins back into the same places, one per plugin you noted in step 1:
sudo cp -a /var/www/moodle.old/public/mod/<name> /var/www/moodle/public/mod/

Before the next step, check each add-on plugin’s page for a version that supports your new Moodle release.

  1. Run the database upgrade, then leave maintenance mode:
sudo -u www-data /usr/bin/php /var/www/moodle/admin/cli/upgrade.php --non-interactive
sudo -u www-data /usr/bin/php /var/www/moodle/admin/cli/purge_caches.php
sudo -u www-data /usr/bin/php /var/www/moodle/admin/cli/maintenance.php --disable
  1. Check the version:
sed -n "s/.*\$release\s*=\s*'\([^']*\)'.*/\1/p" /var/www/moodle/public/version.php

Once you’ve checked the site works (Check everything works), remove the old tree with sudo rm -rf /var/www/moodle.old.

If the upgrade fails, put the old code back (sudo rm -rf /var/www/moodle && sudo mv /var/www/moodle.old /var/www/moodle). If the database upgrade had already started, restore your database backup or cloud snapshot too.

Move to a fresh CloudSOE image

Launching a new instance from the latest CloudSOE Moodle image and moving your site across is the right approach when:

  • you’re moving to a new major Moodle release,
  • Debian 12 is approaching the end of its support, or you want a newer OS,
  • the instance has drifted a long way from a clean state, or you suspect it was compromised before you patched.

The new instance’s Moodle version must be the same as or newer than your old one. Moodle can upgrade a restored database, but never downgrade it.

1. Back up the old instance

On the old instance:

sudo -u www-data /usr/bin/php /var/www/moodle/admin/cli/maintenance.php --enable

mkdir -p ~/migration
sudo mysqldump --single-transaction moodle | gzip > ~/migration/moodle-db.sql.gz
sudo tar czf ~/migration/moodledata.tar.gz -C / var/moodledata
sudo cp /var/www/moodle/config.php ~/migration/config.php.old
sudo chown -R $(whoami) ~/migration

While you’re there, note your additional plugins (Site administration → Plugins → Plugins overview → Additional plugins). On the new instance, install versions of them that support the new Moodle release.

2. Launch the new instance

Launch the latest CloudSOE Moodle image, following the AWS or Azure getting-started guide. Let first boot finish (systemctl status moodle-firstboot). It installs a fresh, empty Moodle, which your restore replaces.

3. Copy the backup across

From your own machine, use debian on AWS or your chosen admin user on Azure:

scp -r debian@<old-ip>:migration ./migration
scp -r ./migration debian@<new-ip>:

4. Restore on the new instance

On the new instance:

sudo -u www-data /usr/bin/php /var/www/moodle/admin/cli/maintenance.php --enable

# Database: replace the fresh site created at first boot
sudo mysql -e "DROP DATABASE moodle; CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
gunzip -c ~/migration/moodle-db.sql.gz | sudo mysql moodle

# Data directory: replace it with yours
sudo rm -rf /var/moodledata
sudo tar xzf ~/migration/moodledata.tar.gz -C /
sudo chown -R www-data:www-data /var/moodledata
sudo chmod 770 /var/moodledata
sudo chmod -R g+w /var/moodledata

The moodle database user and its privileges survive the drop and re-create.

Keep the new instance’s config.php. It holds the new instance’s unique database password. Compare it with config.php.old:

  • Set $CFG->wwwroot to the address your users will use. That’s your domain, or the new IP if you don’t have one.
  • Copy across any settings you added yourself, such as proxy, SMTP or cache settings, or $CFG->passwordsaltmain if your old file has one.
sudo nano /var/www/moodle/config.php

Next, copy in your add-on plugins (versions for the new release) under /var/www/moodle/public/ as in Upgrade Moodle. Then upgrade the restored database to the new code and reopen the site:

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

Your users, courses and passwords come across with the database. The generated admin password in /opt/moodle/default-moodle-credentials.txt no longer applies, so log in with your existing admin account. The database password in that file is still correct.

5. Switch traffic and retire the old instance

  1. Point your DNS A record at the new instance’s IP. You can also move the address itself: on AWS, re-associate your Elastic IP with the new instance; on Azure, dissociate the static public IP from the old VM’s network interface and associate it with the new one. Make sure $CFG->wwwroot matches the final address.
  2. Once DNS points at the new instance, request a new trusted certificate there with sudo certbot --apache -d moodle.example.com. See the configuration guide.
  3. Stop (don’t delete) the old instance and keep it for a few days. It’s still in maintenance mode, so nobody can make changes there by accident.
  4. When you’re happy, terminate or delete the old instance, its disks and the snapshots you took for this upgrade.

Check everything works

After any patch, upgrade or migration:

# Services are running
systemctl status apache2 mariadb --no-pager

# PHP is patched, and the php command is 8.4
php -v

# Moodle version
sed -n "s/.*\$release\s*=\s*'\([^']*\)'.*/\1/p" /var/www/moodle/public/version.php

From your own machine, since an Azure VM often can’t reach its own public IP:

curl -skI https://<public-ip>/login/index.php

Then, in Moodle:

  • Site administration → Notifications should show no pending upgrades and confirm that cron is running.
  • Site administration → Server → Environment should pass for your Moodle release.
  • Site administration → Reports → Security checks shouldn’t flag any critical problems.
  • Log in as a test student and open a course, a quiz and an uploaded file.

Next steps