IT training resources & rants

View My GitHub Profile

Update and upgrade Moodle using Git

Git provides the easiest way to manage Moodle code, including updates and upgrades. An update is a minor version change such as from 3.3.2 to 3.3.3 for example, whereas an upgrade involves a major version change such as from 3.3 to 3.4. These examples were all run on CentOS Enterprise Linux 7 but should be similar for any Linux distro.

Make backups

Regardless of whether you are updating or upgrading, start by backing up your Moodle installation:

cp -a /path/to/moodle /path/to/moodle.bak

Then backup your database (PostgreSQL used in this example):

pg_dump -U db_user db_name > db_backup.sql

Enable maintenance mode

Next, change into the Moodle installation directory and enable maintenance mode (this temporarily takes Moodle offline):

cd /path/to/moodle
php admin/cli/maintenance.php --enable

Option 1: Update

To update to a newer minor version, simply pull the latest updates using git:

git pull

Option 2: Upgrade

To upgrade to a newer major version, update git’s branch data, checkout the new branch, then pull the latest upgrade. In this example we are upgrading to 3.4:

git remote update
git checkout -b MOODLE_34_STABLE origin/MOODLE_34_STABLE
git pull

Next, upgrade the database using the CLI tool:

php admin/cli/upgrade.php

Optionally, now remove the old branch (3.3 in this example):

git branch -d MOODLE_33_STABLE

Disable maintenance mode

When finished, disable maintenance mode:

php admin/cli/maintenance.php --disable

Finally, check that the version number is correct under Site administration → Notifications.

Also check whether any contributed plugins now require upgrading under Site administration → Plugins → Plugins overview → Check for available updates.