Moodle on my intranet: switching to Git to make upgrades painless

Rod Tatham's picture
Rod Tatham

Drupal has a number of interesting elearning modules available, but a lot of our charity clients choose to use Drupal and Moodle together on their intranets.

Upgrading Moodle can be a rather forbidding task, but using git simplifies this process enormously.

We learnt a couple of golden rules:-

using the command line to upgrade was much more reliable and much quicker than using the web interface

we only restored the themes and content from the config.php file from the old version - not the Moodle modules. This is because restoring out-of-date modules caused grief, and weren't really needed. Your mileage may vary!

Here is a step-by-step account of how we achieve this. The process is well-documented on Moodle. Our starting point was Moodle 2.7, but if yours is an early version, you'll need to upgrade to 2.7 first.

1) First of all, check the database is in the correct format (default storage engine = InnoDB). You can find this, if you're using PHPMyAdmin, by looking under the 'Varibles' tab and searching for 'InnoDB'. This was already fine for us, but you may need to address this.

2) put your site into maintenance mode and back up your data

cd /var/www/sites/moodle/
sudo /usr/bin/php admin/cli/maintenance.php --enable

3) move the whole site directory (eg /var/www/sites/moodle) somewhere safe - you'll need this later!

4) use Git to download a fresh, up-to-date copy of Moodle. Read the Moodle documentation here.

 cd /var/www/sites
 git clone git://
 cd moodle
 git branch -a
 git branch --track MOODLE_31_STABLE origin/MOODLE_31_STABLE
 git checkout MOODLE_31_STABLE

5) open the new 'config-dist.php file', and manually merge in the relevant content from your old config.php. Save it as config.php.

6) copy any themes that you still need out of your old 'themes' directory, and paste into the new one.

7) now run the update script from the command line. We found this much easier than attempting the upgrade through the browser:

sudo /usr/bin/php admin/cli/upgrade.php

8) take your site out of maintenance mode:

cd /var/www/sites/moodle/
sudo /usr/bin/php admin/cli/maintenance.php --disable

9) go back to your site in the browser. Check the new version in the Environment report. There's a 'clear cache' button at the bottom if you need it.

In our case, we followed the advice to update the InnoDB table formats to Barracuda.

sudo /usr/bin/php admin/cli/mysql_compressed_rows.php --fix

10) now check the plugins, and fix any issues with them (issues are highlighted in pink):

That's it!

Switching to Git should make future updates and upgrades fairly painless with a simple 'git pull' command!