IT training resources & rants

View My GitHub Profile

Manage Moodle using Git

Git provides the easiest way to manage Moodle code, including installation, 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.

The official Moodle git repository is located at git://git.moodle.org/moodle.git.


Installing Moodle directly from Git is a simple process. First, change into the webroot directory:

cd /path/to/your/webroot

Next, clone the upstream (i.e. the remote server based) moodle.git repository into the webroot directory. The upstream repository is called origin by default. This step creates a new directory named moodle, into which all file are downloaded. This step can take a while as it is actually getting the entire history of all Moodle versions:

git clone git://git.moodle.org/moodle.git

Change into the newly created directory:

cd moodle

List all available branches:

git branch -a

Assuming that the latest stable branch is Moodle 3.5, create a new local branch called MOODLE_35_STABLE and set it to track the remote branch MOODLE_35_STABLE from the upstream repository:

git branch --track MOODLE_35_STABLE origin/MOODLE_35_STABLE

Check out and switch to the newly created local branch:

git checkout MOODLE_35_STABLE

The Moodle code is now installed and ready for the normal installation process.

Updating and Upgrading

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.