In this post, I describe how to upgrade a Moodle installation from one major version to a newer one using the command line and git.
When it comes to open-source e-learning platforms, Moodle is pretty much the only game in town. With masses of features and numerous contributed plugins, it's very powerful and customisable. On the downside, it has a very heavy performance footprint, and upgrading it can be rather an involved process. There aren't any helpful Debian packages and the documentation is a bit patchy in places. Using git to keep Moodle up to date takes a lot of the pain away, but it's still difficult to find clear step-by-step instructions. The following guide collects together a few bits of information I've collected about git and Moodle from various places on the internet.
- Back up your Moodle installation:
cp -a /path/to/moodle /path/to/moodle.bak
mysqldump -u [moodle_database_user] -p [moodle_database_name] > moodle_database_backup.sql
- Enable maintenance mode and switch to the newer branch — you can skip the branch checkout if you're only upgrading between minor versions. Replace
XYwith the correct version number, e.g. 26 for Moodle 2.6.x:
$(which php) admin/cli/maintenance.php --enable
git remote update
git checkout -b MOODLE_XY_STABLE origin/MOODLE_XY_STABLE
- Upgrade the database and disable maintenance mode:
$(which php) admin/cli/upgrade.php
$(which php) admin/cli/maintenance.php --disable
- Login to the site and check the version number is correct on Site administration → Notifications
- Upgrade any contributed plugins by visiting Site administration → Plugins → Plugins overview and clicking “Check for available updates”.
- (Optional) Remove the old branch with
git branch -d MOODLE_AB_STABLEwhere
ABis equivalent to the old version number, e.g. 25 for Moodle 2.5.x.