Upgrading Moodle 3.11 to Moodle 5.1.3

Overview

I have been wondering whether I can upgrade my Moodle 3.11 to the latest version. My Moodle 3.11 has many great courses, the most I have ever taught, and a large volume of data to analyze. Real student and course data!

My typical procedure for accessing Moodle 3.11 is to use MAMP. Can this Moodle 3.11 instance be upgraded to the current version, Moodle 5.1.3 (Build: 20260216)?

I decided to give it a try in February 2025. Yes, I was successful. I describe my process below.

 

The recommended path for upgrading Moodle.

2.2 -> 2.7 -> 3.1 -> 3.6 -> 3.11.8 -> 4.2.3 -> 5.0

Strategy

I use MAMP on my Mac because it meets Moodle 3.11 through 5.1.3's PHP and database requirements. Moodle 5.1.3 requires modifying environment.xml in MAMP. Once MAMP is working, I will migrate it to a new Moodle on my production server.

 

Versions for MAMP

Versions for edu-gen.com

Moodle Versions

 

For this upgrade in MAMP, I adopted a moodle3-5 designation; as in moodledata3-5, moodle3-5, and a moodle3-5 database.

On my production server, I adopted a moodle3 designation; as in moodledata3, moodle3, and a moodle3 database.

Also, I decided to put moodledata into mdl_data, and moodle into mdl_sites, because I knew that that would be where I would want to end up. I created a symlink to Moodle, which is needed for Moodle 5.1 and upwards.

The MAMP Moodle3-5 provides a good experimental environment.

My path for upgrading Moodle is 3.11.8 -> 4.2.3 -> 4.5.10 -> 5.0 -> 5.1.3.

Preparation

Duplicated Moodle 3.11

I began by duplicating my Moodle 3.11 site in MAMP. It was easy to copy the moodledata3 folder to a new moodledata3-5 folder. I copied the moodle3 folder to a new moodle3-5 folder in the mdl_sites/ folder. I created a new database for moodle3-5. For whatever reason, the mysqldump command was problematic. I couldn't import its database into moodle3-5. So, I decided to use phpMyAdmin, picking “custom” export, but making no other changes. I successfully imported the data into my new moodle3-5 database using the normal MySQL command to import a database.

I edited config.php for the new locations.

I created a symlink to moodle3-5 with the following command: ln -s ../mdl_sites/moodle3-5/ moodle3-5.

Although making the duplicate required a few attempts, I eventually got everything working.

Removed Plugins

For the plugins, I removed their folders rather than uninstalling them through Moodle's web interface. I did this to preserve their data.

Ad-hoc database queries: Removed. Upgraded database. No problems.

Extra Fonts: Removed. Upgraded the database. No problems.

Block checklist: Removed. Upgraded the database. No problems.

Configurable Reports: Removed. Upgraded the database. No problems.

Mod Checklist: Removed. Upgraded the database. No problem

Collapsed Topic: Before removing Collapsed Topics, I switched the format for about a half-dozen courses to the “topic” format. I then removed Collapsed Topics and upgraded the database. No problems.

At this point, under Additional plugins, my plugins showed as “missing from disk,” as expected.

Removed Custom CSS

I decided to leave my custom CSS in place, at least for now.

Purged Caches and Ran cron

Lastly, I ran purge_caches.php and cron.php a few times to clean things up. I did this from Terminal using CLI script files in Moodle's admin/cli/ folder. I plan to do this after each step.

Ready to Go

My Moodle 3.11 was now ready for the upgrade.

Upgrade to Moodle 4.3.12

The version of Moodle 4.3 available from Moodle.org downloads was version 4.3.12.

When I first tried to upgrade to Moodle 4.3.12, I got a blank screen. Then I remembered that Moodle 4.3.12 required PHP version 8.2.20. After I changed PHP to 8.2.20 in MAMP, the upgrade succeeded. However, the appearance was slightly strange. I removed all CSS. I went into a course, and then things looked more “normal.” The strange appearance might have been a browser cache issue.

I ran purge_caches.php and cron.php a few times from Terminal.

Upgrade to Moodle 4.5.10 (latest 4.5)

Next, I upgraded from Moodle 4.3.12 to 4.5.10.

During the upgrade, a suggestion was to enable asynchronous backup. I ignored it for this Moodle version.

This upgrade appeared to work fine.

I ran purge_caches.php and cron.php a few times from Terminal. Running cron.php gave me some trouble. It said “pending Moodle upgrade.” But then, it worked!

Everything looked good.

Upgrade to Moodle 5.0.6

Next, I upgraded to Moodle 5.0.6 (Build: 20260216). I wanted to upgrade to Moodle 5.0 before 5.1 because of the significant revisions to the question bank.

Because Moodle 5.0.6 requires MySQL 8.4 and MAMP 7.1 only has MySQL 8.0.35, I had to modify the environment.xml file to change the required MySQL version from 8.4 to 8.0 for this to work.

Again, I had some problems running cron.php. After a few attempts, it finally worked.

Upgrade to Moodle 5.1.3 (latest 5.1)

When I duplicated Moodle 3.11 earlier, I had already moved the Moodle code outside of htdocs and created a symlink, so I had already met Moodle 5.1's requirements.

Again, I had to edit the environment.xml file to resolve the MySQL database issue.

I ran purge_caches.php and cron.php a few times from Terminal. This went well.

Everything went well.

I now had successfully upgraded Moodle 3.11 to Moodle 5.1.3.

Migrate to Edu-Gen

It now made sense to move this MAMP Moodle to my production environment, which is referred to as a "migration." In general, you do this by backing up your Moodle and then restoring it to the new server environment. My first step in the migration is to install a fresh copy of Moodle 5.1.3 on my server and verify that it works. If you cannot get a new Moodle instance working, it is unlikely that a migration will succeed.

On edu-gen.com, I installed Moodle 5.1.3. I used "3" as the convention: moodle3, moodledata3, moodle3 (db), moodle3 symlink.

I backed up the database using phpMyAdmin in MAMP, and tar'd the moodledata folder (about 10GB). I ftp'd these up to my server. I had to make sure that I had enough space, so this was a good time to clean my production server. I had a bunch of experimental moodles to remove.

I always begin by "dropping" the database tables on the target database.

Importing the database was frustrating. The phpMyAdmin export didn't work, perhaps because my Moodle 3.11 database is around 3GB. Or it might also have been a problem with two "view" tables in the original Moodle 3.11, so I removed them. Finally, I used the mysqldump command on the MAMP database, which successfully imported into the server's database. The command is:

mysql -uedugen_mdl -p(password) edugen_moodle3 < moodledb3dump.sql

I replaced the moodledata3 folder with my backup of the moodledata3 folder, removing some of the Mac "." files.

I added a cronjob for this new moodle3 application.

Finally, I had success.

Match my Newest Moodle 5.1

At this point, my upgraded Moodle 3.11 worked, but I wanted it to match some of my newest changes, and fix a few issues.

 

Everything was looking good. I now have my old Moodle 3.11 available on my production server. I plan to use this version whenever I need to explore anything from my extensive list of old courses, around 70.

 

Doing the upgrade using MAMP seemed like a good strategy.

Future Things to Explore

Explore the Question Bank changes.

Are there any grade book issues?

Are any sql queries not working due to database table changes?