Moodle Plugins directory: Alternative File System | Moodle.org
Alternative File System
This plugin allows transferring all files from the moodledata/filedir directory to cloud storage.
With this plugin, it is possible to transfer files to AWS S3 or DigitalOcean Spaces (S3-compatible).
Advantages of using cloud storage instead of local files in Moodle
By transferring files to remote storage (such as AWS S3 or DigitalOcean Spaces), you gain several advantages compared to keeping files locally.
Main benefits:
- Server resource optimization:
- Moving files to the cloud reduces local disk usage and simplifies server operations.
- When combined with a CDN (when applicable), part of the traffic can be served with lower load on the Moodle server.
- Scalability:
- S3/Spaces storage allows you to grow storage capacity without relying on server disk expansion.
- Makes it easy to increase storage as demand grows, without complex hardware migrations.
- Reliability:
- Cloud storage provides high availability and object durability.
- Reduces the risk of downtime and data loss caused by disk failures on the local server.
- Performance:
- S3-compatible services can be integrated with a CDN to improve file delivery, especially for users far from the server.
- In many scenarios, this improves load times and the user experience.
- Security:
- You can apply access control, policies, encryption, and access auditing at the bucket/space level.
- By storing files remotely, you can strengthen security practices and reduce the impact of incidents on the local server.
By choosing remote storage instead of local Moodle storage, you benefit from the scalability, reliability, performance, and security offered by S3/Spaces solutions. This improves the user experience and simplifies operations in larger environments (including clustered setups).
Implementation
After installing the plugin, you must edit the config.php file and add the line below before the call to require_once( __DIR__ . '/lib/setup.php' );.
$CFG->alternative_file_system_class = "\\local_alternative_file_system\\external_file_system";
This line changes the file system class to the one provided by the plugin. Make sure it is added in the correct location in config.php for proper operation.
To complete the installation and move the objects to the cloud, follow the steps below according to the chosen service:
AWS S3
- Create an AWS account:
- If you don’t already have an account, create one at aws.amazon.com.
- Access the AWS Console:
- Log in to the AWS Management Console.
- Create an Amazon S3 bucket:
- In the console, go to Amazon S3 and create a new bucket.
- Choose a unique name and select the desired region.
- Configure access permissions:
- Create/adjust IAM policies to allow Moodle to access the bucket with the minimum required permissions.
DigitalOcean Spaces
- Create a DigitalOcean account:
- If you don’t already have an account, create one at digitalocean.com.
- Access the DigitalOcean Console:
- Log in to the DigitalOcean dashboard.
- Create a Space:
- In the console, go to “Spaces” and create a new Space.
- Choose a unique name and select the desired region.
- Generate access keys:
- Generate access keys/credentials with appropriate read and write permissions for the Space.
Migration
There are two main scenarios:
Scenario A) Migration from local filedir (moodledata/filedir → cloud)
- Configure the destination in the plugin (S3/Spaces).
- Use the plugin’s migration mechanisms/routines (existing scripts).
Scenario B) Import/Migration from tool_objectfs (ObjectFS → local_alternative_file_system)
At the request of users/clients, support was added to import objects stored in tool_objectfs and copy them to the destination configured in this plugin, allowing migration with minimal downtime.
How the strategy works (without stopping the site)
The migration happens in 2 phases:
Phase 1 — Moodle continues using tool_objectfs (normal production)
While Moodle is configured with:
$CFG->alternative_file_system_class = "\\tool_objectfs\\...";
- The site continues to read/write normally via
tool_objectfs. - CRON runs a task that copies objects from
tool_objectfsto the destination configured inlocal_alternative_file_system.
In other words, you “duplicate” the objects to the new destination without interrupting the site.
Phase 2 — After copying is complete, switch the AFS to this plugin
When the report indicates that migration is finished (100% / no pending items), change config.php to:
$CFG->alternative_file_system_class = "\\local_alternative_file_system\\external_file_system";
From that point on, Moodle will serve/read files directly via local_alternative_file_system.
Monitoring / Progress Report
Use the plugin’s report to track:
- total hashes
- migrated
- missing
- rate (last minutes)
- estimated ETA
Access:
https://YOUR-MOODLE/local/alternative_file_system/report-migrate.php
Tip: during Phase 1 (tool_objectfs active), this report helps you decide the right moment to switch the $CFG->alternative_file_system_class.
Best practices and notes
- Perform migrations during off-peak hours.
- Adjust CRON batch sizes/timers according to the size of your environment.
- After switching the AFS to this plugin, monitor the report for a period to ensure there is no “residual queue”.
- If you use a CDN, validate headers/content-disposition according to your download policies.
I am using moodle 4.1
what should I do?
$CFG->alternative_file_system_class = "\\local_alternative_file_system\\external_file_system";
I like this plugin, it's great Job.