Note: You are currently viewing documentation for Moodle 2.1. Up-to-date documentation for the latest stable version is available here: Upgrading to Moodle 2.1.

Upgrading to Moodle 2.1

From MoodleDocs

You can upgrade to Moodle 2.1 from Moodle 2.0 or 1.9. If you are upgrading from 1.9, please read the Upgrading to Moodle 2.0 page too. If you are using an earlier version of Moodle, you must upgrade to the latest Moodle 1.9.x first.

We advise that you test the upgrade first on a COPY of your production site, to make sure it works as you expect.

System requirements

  • Moodle must be 1.9 or later (consider upgrading to 2.0 before upgrading to 2.1)
  • PHP must be 5.3.2 or later
    • Required PHP extensions: iconv, curl, ctype, zip, simplexml, spl, pcre, dom, xml, json
    • Required PHP memory_limit at least 40MB (64MB or more recommended if you have a choice)
  • Databases should be one of the following:
    • MySQL 5.0.25 or later (InnoDB storage engine highly recommended)
    • PostgreSQL 8.3 or later
    • Oracle 10.2 or later
    • MS SQL 2005 or later
  • Any standards-supporting browser from the past few years, for example:

Moodle 2.1 planning

The biggest change in Moodle 2.1 that affects the upgrade is the new question engine. If you have lots of quiz attempts, you need to plan this upgrade carefully. If you don't have lots of quiz attempts, you don't have to worry.

Planning the question engine upgrade

The upgrade from Moodle 2.0 to 2.1 needs to do a major transformation of all the quiz attempt data. This is something you need to plan for if you have a lot of quiz attempts.

To gauge whether this will be a problem for you, count the number of rows in the question_sessions table:

SELECT COUNT(1) FROM mdl_question_sessions;

  • If this number is less than something like 10,000 then you have nothing to worry about.
  • If this number is greater than something like 1,000,000 then you have to plan.

A helpful plugin

There is a useful plugin you can install to help you plan the upgrade which you can install from If you have a significant number of you are strongly advised to install it.

Once installed, you can access it using the Question engine upgrade helper link in the Site administration menu. This plugin has various features.

The List quizzes and attempts option will count the number of quiz attempts and question sessions (like the query above) but giving more detail. Again, this is a way to get an idea of the scope of the upgrade for you.

What to do if you have a lot of attempts

Here are some options to consider:

Think about whether you really need to keep them all.
If you have not thought about your archiving strategy for old quiz attempts before, then this would be a really good time to do so. Do you really need to keep all the old data around? If not, deleting it before you upgrade to 2.1 would be a good idea.
If you just need access to the old attempts for archival purposes, perhaps you could achieve that by keeping a copy of your old site from before the upgrade, and then only keeping and upgrading the current quiz attempts on your live system.
Upgrade some of the attempts later
The technical details for how to do this are in the script partialupgrade-example.php which you will need to edit.
After the upgrade, you can complete the upgrade in one of two ways:
  1. You can manually use the Question engine upgrade helper to upgrade the attempt data for any quiz that has not already been done. Use the List quizzes still to upgrade option.
  2. You can set up cron to automatically complete the upgrade using the Configure cron option.

How to check that the upgrade was successful

If you want to verify that the upgrade worked successfully, here are some things to check:

  • Obviously, look out for any error messages output, or written to the logs, during the upgrade.
  • The upgrade also writes a file into moodledata/upgradelogs/upg_{timestamp}.html. This lists any places where there were problems with the data in your database, and the upgrade code had to make an assumption about how to proceed. This log file should be self-explanatory, if a bit technical, and it most cases each problem report will include a link to the quiz review page, so you can easily see the result of the upgrade.
  • Finally, if you are testing the upgrade on a copy of your site, you can pick some example quizzes, and open the quiz reports or review pages from before, and after, the upgrade in separate browser windows, and compare to make sure the data is the same. Of course, there will be some differences (we hope the new system is better!) but this does let you check the data.

What to do if something goes wrong during the upgrade

I am sure you started by testing the upgrade on a copy of your live site, so if anything goes wrong, you can report the bug, wait for it to be fixed, and then try again.

If you wish to report a bug in the upgrade you may want to look at the instructions on dev:Question_Engine_2:Testing about how to make the bug report as useful as possible.

After the upgrade, you can use the Question engine upgrade helper plugin to re-do the upgrade of the attempts at any particular quiz. This should let you fix problems, even if you only discover them later. You can do this by using the List already upgrade quizzes that can be reset and List quizzes still to upgrade options.

Before upgrading please...

NOTE: The upgrade process will irreversibly modify the contents of your database and your moodledata file storage area. If something goes wrong you cannot go back. It is vital that you take good backups of both moodledata and the database in case you have problems with the upgrade. If you are not sure how see Site backup or ask in the forums (explaining what your operating system is).

  • It's a good idea to read the dev:Moodle 2.1 release notes and check the list of new features.
  • Always check your site to make sure it meets all system requirements for 2.1 in Administration > Server > Environment
  • Do a full database backup!
  • Do a full moodledata backup
  • Check your backups carefully
  • Remember to purge PHP cache if using any PHP accelerator

A word about optional plugins and themes

If you have added optional or customised plugins (whether your own custom developments or from the modules and plugins database) or are using a non-core theme then these will probably work in Moodle 2.1+ if they worked in Moodle 2.0 with the following exceptions:

  • Question types.
  • Activity modules that use the question bank. (There are hardly any of these.)

Again, you are advised to test the upgrade on a copy of your Moodle site.

Checking database schema - old sites

If your 2.0 Moodle site has been upgraded through many prior versions it is possible that there will be some problems with the database schema (compared to a fresh 2.0 installation). This may cause the upgrade to fail. If your site started life prior to Moodle 2.0 it is a very good idea to check and correct the database schema before upgrading. See Verify Database Schema. You should also run the database integrity checks in the XMLDB editor, see the 'See also' for a link to extra scripts to check for other discrepancies.

Now upgrade

Once you have satisfied the requirements for Moodle 2.1, follow the instructions on the upgrading page.

On Linux servers, Moodle 2.1 supports running the upgrade from the command line, rather than through a web browser. This is likely to be more reliable, particularly for large sites.

After upgrade

The config.php file from your 2.0 installation should work fine but if you take a look at config-dist.php that came with Moodle 2.0 there are more/different options available (e.g. database drivers and settings). It's a good idea to map your old config.php settings to a new one based on the 2.1 config-dist.php.

Known and discovered Issues

  • If you get an error about 'handling of PHP float numbers', please see the FAQ about it in the Installation FAQ.
  • You now need some additional PHP modules installed (e.g. intl and the zip extension). If you do not have these, installation them depends entirely on how your PHP was first installed and your operating system.

MySQL dmlwriteexception error when using calculated questions in a quiz

If you're using MySQL or SQL*Server and you have a problem with duplicated keys with the question_attempt_step_data table when using calculated questions in a quiz (from entering a formula which uses variables with the same characters in different cases), it is recommended that you upgrade to Moodle 3.0.x or higher ASAP. Alternatively, the problematic unique index can be dropped or the collation of the columns changed to be case-sensitive, however this is not considered a complete fix. See MDL-29332 for more information.

See also