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
Installing Moodle directly from Git is a simple process. First, change into the webroot directory:
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:
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.
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
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
To update to a newer minor version, simply pull the latest updates using git:
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:
Optionally, now remove the old branch (3.3 in this example):
git branch -d MOODLE_33_STABLE
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.