Why Moodle dataroot planning comes before the server build
Decide where moodledata lives and how large it can grow before you build the web or database servers, because that choice shapes almost everything after it. The dataroot holds the files users upload to courses, backup archives, cached data, temporary files and session-related content. It is separate from the Moodle code, and it is the part of the installation that grows with use, changes constantly and must be backed up on its own schedule. Treat it as a storage design with its own owner, not as a folder created during installation.
The placement affects four things you will have to live with: backups, file locking, scaling and upgrades. Backups need a dataroot you can snapshot or copy consistently alongside the database, so the database and the files must be captured together. Locking depends on the file system underneath, and the Moodle config.php template warns that some file systems, including NFS, may not support file locking and recommends locking for production servers. Scaling to more than one web server means the dataroot must be shared or moved to a store every node can reach. Upgrades rely on the same files being intact and writable by the right account, so a dataroot that was never planned tends to turn each upgrade into a manual repair.
The 5.1 change to the web server document root makes the split between code and data a routine check rather than a one-time setting. From Moodle 5.1, the web server must point at the /public directory, and the dataroot must sit outside that web-accessible tree. Before you write the server configuration, confirm the planned dataroot path, the owner and permissions of that directory, the size you expect for backups and media in your first year, and whether your chosen file system supports the locking Moodle needs. Check the exact requirements in the Moodle 5.1 release notes for your target release.
Which file storage option fits which deployment
This table compares four ways to store moodledata: local disk, a network file share, a clustered ReadWriteMany volume, and object storage through objectfs or an alternative file system class. Read each row to see when the option fits, what it does to locking and consistency, how backups change, and how much ongoing operational work it adds. The main takeaway is that the locking caveat in config-dist.php pushes most multi-server designs toward a shared file system that supports locking, or toward a plugin that keeps files off the dataroot.
| Option | Best fit | Locking and consistency | Backup and operations |
|---|---|---|---|
| Local disk on a single server | One web server, one database, modest upload volume, and a team that can restore the server as a unit | No network locking concern because all processes share one local file system | Simple to snapshot with the server, but dataroot backups must be scheduled separately from the database dump |
| Network file share (NFS or similar) | Several web or cron servers that must see one dataroot and an existing file server the organization already runs | config-dist.php warns that NFS may not support file locking and strongly recommends locking for production; confirm lock behavior with your storage vendor before go-live | Backups depend on the share's own snapshot tooling; test restores of both the share and the matching database |
| Clustered or ReadWriteMany volume | Kubernetes or multi-node deployments that need a shared dataroot and tempdir on one volume | Locking behavior depends on the volume driver; verify it against the config-dist.php locking guidance before relying on it | Volume snapshots and replication add cost and skills; the backup set must stay consistent with the database at the same point in time |
| Object storage through objectfs | Large media volumes where local or network disk growth is the main cost, and teams ready to manage a plugin and its object store | Moves file content off the dataroot, so the locking question shifts to how the plugin and object store handle concurrent writes; confirm with the plugin documentation | Backups must cover both the database and the bucket, and restores need a tested procedure for both; ongoing effort includes plugin upgrades and bucket lifecycle rules |
| Alternative file system class | Sites that need a custom file handler through the alternative_file_system_class setting in config-dist.php | Behavior is defined by the class you write or adopt, so locking must be tested rather than assumed | Adds code you own; plan for upgrades, testing with each Moodle release and documentation of the handler |
Setting up moodledata outside the web root
This sequence places moodledata on a path the web server cannot reach, locks its ownership to the PHP runtime user, and proves that uploads, backups and cron write to it. The result is a dataroot that is writable by Moodle and not browsable by anyone else.
Choose a dataroot path outside the document root
Decide on an absolute path that sits outside the web server document root and outside the Moodle code directory, for example a dedicated volume mounted under a data path on the application server. Record the path, the mount source and whether it is local disk or a network mount, because later steps depend on it. Confirm with your platform team that the volume is backed up and sized for uploads and backups. Done when the path is written in your build notes and no part of it is reachable through the site's URL space.
Create the directory with the runtime user as owner
Create the directory as root, then set the owner and group to the user that runs PHP-FPM or the web server process, which varies by distribution (for example www-data on Ubuntu). Confirm the account with the process list or the PHP-FPM pool configuration rather than assuming it. Done when
ls -ldon the directory shows the expected owner and group, and a test file created as that user succeeds.Apply restrictive permissions to the dataroot
Set the directory to owner-only access so that other local accounts cannot read uploaded files, sessions or cache entries. Apply the mode recursively only to the dataroot, not to the Moodle code. Check that the cron user, if different from the PHP-FPM user, is either the same account or is added to the group that owns the dataroot. Done when a login as an unrelated local account cannot list or read the directory, and the runtime user can still create and delete files there.
Set dataroot in config.php
Add the absolute path to the
$CFG->datarootsetting inconfig.phpin the Moodle root, using the path chosen in the first step. Leave$CFG->wwwrootunchanged. If your deployment uses a separate temp or cache location, set those keys here as well so they stay outside the web root. Done when the Moodle administration pages load without a dataroot error and the path reported on the environment page matches the intended directory.Point the web server at the public directory
On Moodle 5.1 and later, set the web server document root to the new
publicdirectory inside the Moodle code, not the main Moodle folder. If the document root still points at the code root, the site may show directory listings or errors, and the dataroot may sit beside files that the web server can expose. Reload the web server after the change. Done when the site loads from the public directory, the environment check raises no document root warning, and requests for paths in the code root return not found.Confirm the web server cannot serve dataroot
Request a known file from the dataroot through the browser, using the site's domain and a path that would map to it if the document root were misconfigured. Also test a path traversal attempt through the front controller. Review the web server access log for the response codes. Done when every request for dataroot content returns a not-found or forbidden response and no file contents appear. Record the test in your change record for the security review.
Verify uploads, backups and cron write to dataroot
Upload a test file through a course or user profile, run a manual course backup from the administration area, and confirm that a scheduled task runs under the cron user. Then list the dataroot subdirectories that changed, such as filedir and temp, and confirm the new files are owned by the expected account. Done when each action produces files in dataroot, the cron run completes without permission errors in the Moodle logs, and no files were written to the web root.
Security controls for files that users upload
Files uploaded to Moodle, including assignment submissions, course media and backups, sit in moodledata and can be read by anyone with access to that directory. The controls below work together: keep the directory unreachable from the web, limit who and what can read it, and protect the copies that leave the server. Confirm each setting in your own environment before go-live.
Block direct web access to dataroot
Moodle serves files through its own PHP access checks, so moodledata should never be reachable by a URL. Place it outside the web root, and confirm that your web server returns an error for any request that tries to reach it directly. Since Moodle 5.1 the document root must point to the /public directory, which keeps the rest of the code tree away from the web. Test with a known file path after each change to the web server configuration, and repeat the test after upgrades.
Moodle 5.1 notesScope file permissions tightly
Only the web server process and the cron user should be able to read and write moodledata. Other local accounts, including administrators who do not need file access, should not have read rights to the directory. Ask your platform team to document the owner, group and mode for moodledata and tempdir, and to check them after restores, because backup tools and container volumes often change ownership. Permissions that are too open are a common cause of exposed uploads.
Separate dataroot from the code tree
Keep moodledata and the Moodle code on different paths, and ideally on different volumes or mounts. Code can be replaced during upgrades or rebuilt from an image, while dataroot holds user content that must persist. Separation also means a code deployment cannot overwrite uploads, and a faulty deploy cannot silently remove them. Confirm that config.php points to the dataroot path you intend, and that deployment tooling never deletes or syncs that path.
Encrypt and restrict backups
Backups of the database and moodledata together contain every uploaded file and every personal record, so they need the same protection as the live site. Confirm whether your backup tool encrypts data at rest and in transit, who holds the keys, and where copies are stored. Restrict restore rights to named operators, and log restore actions. Ask your backup provider to show how a backup set is retrieved and decrypted, so you know the process works before an incident.
Control who reads files at the storage layer
Storage administrators, hypervisor operators, and cloud account roles can often read a volume or bucket without ever logging into Moodle. Inventory every principal with access to the NFS export, block volume, or object store that holds moodledata, and remove standing access that is no longer needed. For object storage, confirm that bucket policies deny public reads and that access logs are retained. Review this list at each staff change and at each release cycle.
Verify the controls on a schedule
Controls drift after upgrades, restores, and infrastructure changes, so they need a repeatable check. Build a short checklist that covers the direct access test, the permission listing, the path in config.php, the backup encryption status, and the storage access list. Assign an owner and record the date of each check. Ask your security team whether they want these results in the same evidence store as your other configuration reviews.
How NFS locking affects a multi-server Moodle
NFS locking is the first thing to test when a shared dataroot spans more than one Moodle web or cron server. Moodle's own config-dist.php warns that some filesystems, NFS among them, may not support file locking, and it states that locking is strongly recommended for production servers. Moodle uses locks on the dataroot to stop two processes from writing the same cache, session or file at once, so a mount that silently ignores locks can produce corruption that looks like random application errors. Treat locking as a go or no-go check before the storage design is approved, not as a tuning item after go-live.
Before choosing NFS for a shared moodledata directory, run a test on the exact mount options, NFS version and server you will use in production. Mount from every web node and the cron host, then confirm that a lock taken on one client blocks a second client from acquiring it, and that the lock releases cleanly when the holder exits or a node is lost. Also check behavior during a brief network interruption, because a stale lock after failover can stall cron or sessions. Record the NFS version, mount options and server export settings in the test report, since a change to any of them can change the result.
Confirm locking on the chosen configuration rather than relying on the protocol name. Ask the storage team which NFS version, lock manager and export options the server uses, and whether the lock service is enabled on every client. If the test fails or the storage team cannot describe the lock path, the alternative is a file system class that does not depend on NFS locking, configured through alternative_file_system_class in config.php, or a different shared storage design. Confirm the current Moodle version's documented options with the Moodle config-dist.php reference before you commit to either route.
What to confirm before sizing storage
Which Moodle version and database minimums apply to my upgrade path?
The release notes set the floor for each version, so confirm the target version first and then its PHP and database minimums. Moodle 5.1 requires 64-bit PHP 8.2 or later, with PostgreSQL 15, MySQL 8.4, MariaDB 10.11 or Microsoft SQL Server 2017 or later, and sites must be on Moodle 4.2.3 or later to upgrade. Moodle 5.3 requires 64-bit PHP 8.3 or later, PostgreSQL 17, MySQL 8.4, MariaDB 11.4 or SQL Server 2019 or later, and sites must run Moodle 4.4 or later. These minimums affect the database host you size, so check them before you commit to a storage layout. See the Moodle 5.1 release notes and the Moodle 5.3 release notes.
Does my NFS or shared storage support file locking reliably?
Ask the storage vendor directly, because Moodle's own configuration file warns that some filesystems, NFS among them, may not support file locking, and it strongly recommends locking on production servers. Get written answers on lock semantics across all client nodes, behavior during failover, and whether the export options you plan to use are supported. If the vendor cannot confirm this, plan for a different file system class or a locking alternative before sizing anything. The reference is the Moodle config-dist.php file.
Will my backup tool handle the dataroot layout I choose?
Confirm that your backup product can back up the dataroot path, any object storage bucket, and the database together with consistent timing. Ask whether it supports snapshots of the file tree, how it handles millions of small files, and whether restores have been tested at the file level as well as the database level. If you use object storage through an alternative file system class, ask whether the backup tool reads the bucket directly or only the local cache. Record the answers before you choose the layout, because changing it later is harder than changing a backup schedule.
How do I measure the media volume my current system produces?
Measure it from the existing system rather than from estimates. Read the size of the current moodledata directory, then compare two snapshots taken a set period apart to see how fast it grows, and separate uploaded files, course backups and cache or temporary content. Also check how many files each course produces, since file count can matter as much as total bytes for backup and restore windows. Use the growth rate to size the next several years, and review the figures with the teams that upload video or large course content, because one large media project can change the picture.
Who pays for storage capacity, and what recurs each year?
In a self-hosted setup you pay for the storage hardware or cloud capacity, the backup copies and the network path, and for the people who run them. Capacity cost recurs because moodledata grows with every upload and every backup retained, so the retention policy is a cost decision as much as a compliance one. One-time costs include the initial build of the file layout, locking tests and restore drills. Ask any partner to split its quote into build work and ongoing operation, and ask which of the storage components they would provision and which your team would buy.
Can my team handle dataroot setup without outside help?
Often yes, if you have a team that already runs Linux file servers, backup systems and a Moodle upgrade routine. The work that usually needs careful testing is the locking and failover behavior of shared storage, the restore drill for the full set of files and database, and the permissions and path rules for the web root. Assess whether your team has done each of those for a Moodle site or a similar application before. If the gaps are in one area only, you may need outside help for that piece alone, and a written scope can separate it from the rest.
What should I ask a partner to include in a storage quote?
Ask for the written scope to name each storage component, the target Moodle version and its minimums, the locking test plan, the backup and restore tests, and the file system class chosen with its reasons. Ask which items are one-time work, which recur as retainer or operating effort, and which depend on your own infrastructure decisions. DeployOpen plans, implements and documents this kind of work inside the client's infrastructure and agrees scope, deliverables and timelines in writing before work starts, so the quote follows from that written scope.
How web, cron and storage layers share moodledata
The diagram starts at the browser, which reaches only the public directory through the web server. PHP-FPM and cron both run Moodle code and write to moodledata, which sits outside the web root and is never served directly. Check that the web server cannot resolve moodledata paths, that cron and PHP-FPM run as the same user, and that the backup job reads moodledata and the database together so the two stay consistent.
Web, cron and backup layers reach moodledata only through PHP-FPM and the trust boundary.
Questions buyers ask about Moodle dataroot and storage
How much effort does a Moodle dataroot and storage design take?
The effort depends on how many storage paths you need to decide and how much of the design already exists. A single-server Moodle with local disk and a planned backup target is a short design exercise. A multi-node setup that needs shared dataroot, a tempdir shared across web nodes, sizing for backups and media, and a decision on object storage takes considerably longer. No researched figure is available for duration, so ask any provider for effort by component: dataroot placement, permissions, shared storage, backup sizing, and the object storage decision. Each item should appear as a line in the written scope.
What does the storage design need from our infrastructure and security teams?
Expect to need your infrastructure team for storage platform details, your security team for permission and access rules, and your backup owner for retention and restore expectations. Infrastructure must confirm the mount types available, whether NFS is offered and how it is configured, and where backups land. Security must confirm who may read the dataroot, how the web service account is separated from administrators, and how uploaded files are handled. Agree these inputs before the design starts, because they decide which options are open.
Can an internal team plan and build Moodle dataroot storage alone?
Yes, a capable Linux and Moodle team can plan and build dataroot storage without an outside partner, provided it reads the configuration reference and tests file locking, permissions and restores in its own environment. The work that most often gets missed is not the directory itself but the shared-storage behavior, the backup restore test, and the rules for object storage. If your team lacks one of those skills, a partner can fill that gap through a fixed-scope design with written deliverables, while your team keeps ownership of the running system.
What drives the cost of dataroot and file storage work up or down?
The main cost drivers are the number of web nodes that must share the dataroot, whether you need shared locking on NFS, how many storage tiers you run, the size and retention of your backups, and whether you add object storage through objectfs or another alternative file system class. A single server with local disk costs little to design. Each added node, storage tier or backup target adds design, testing and documentation. When requesting a quote, ask for the scope split into those items, plus what is one-time work and what recurs, such as capacity reviews and restore tests.
Is NFS safe to use for the Moodle dataroot?
NFS can work for the dataroot, but it needs explicit testing before you depend on it. Moodle's sample configuration file warns that some filesystems, NFS among them, may not support file locking, and it states that locking is strongly recommended for production servers. Confirm with your storage team that the NFS export supports the locking Moodle needs, test it under concurrent load from multiple nodes, and document the mount options. If locking cannot be confirmed, the design should consider another file system class rather than assume it works.
When does objectfs or another alternative file system class make sense?
Object storage through objectfs or another alternative file system class makes sense when file volume is large, when several web nodes need the same files without a shared mount, or when your storage platform already offers an S3-compatible service you run. The configuration reference allows an alternative file system class, so the option is supported at the configuration level. Confirm plugin support for your Moodle version, how backups and restores will cover object data, and who owns the bucket lifecycle before you commit to it.
How should backups be sized for Moodle dataroot files?
Size backups from the dataroot's current content, its growth rate, and your retention period, then add headroom for restore staging. Dataroot holds uploaded files, backups, caches and temporary data, so its size can differ from the database size. Ask the design to list which subfolders are included in backups, how large a full backup and a restore staging area must be, and how long a restore takes in your environment. Test a restore before go-live, because an untested backup is not a backup you can rely on.
How long does a storage design review usually take?
No researched duration is available for a storage design review, so treat any date as something to confirm in writing. The review length depends on the number of nodes, whether NFS or object storage is in scope, how quickly your infrastructure team can supply platform details, and how many test cycles the locking and restore checks need. Ask for milestones in the written scope, with named inputs you must provide, so the timeline is tied to specific dependencies rather than to a general estimate.
How DeployOpen scopes and delivers Moodle file storage
DeployOpen plans, builds, documents and supports the moodledata layer inside your own infrastructure, so the storage path, permissions, backups and locking are settled before users depend on them. Engagements are fixed-scope, with the storage design agreed in writing before build work starts.
How we scope
- Inventory expected file types, upload volumes, retention rules and backup windows for your Moodle site.
- Decide dataroot location, whether it sits outside the web root, and how it is mounted on each web node.
- Agree in writing whether local disk, NFS or an object storage class through objectfs or an alternative file system class fits.
- Confirm the Moodle version and web server document root, including the /public directory requirement from Moodle 5.1.
How we build
- Create the moodledata directory outside the web root with ownership and permissions set for the PHP-FPM or web server user.
- Configure the chosen storage backend and test file locking behavior before any production traffic arrives.
- Size backup targets and media growth against your retention plan, and document the assumptions used.
- Test uploads, restores of moodledata and file access from every web node in a staging copy of your environment.
How we hand over
- Deliver a written storage design covering paths, permissions, mounts, locking settings and the config.php keys used.
- Provide a runbook for checking free space, backup coverage and file restores on a schedule your team can follow.
- Walk your administrators through the configuration so they can explain each setting to auditors or security reviewers.
- Record the decisions and open risks so future changes to storage go through the same review.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers, covering storage changes across Moodle releases.
- Re-test storage paths and backups after Moodle upgrades, server changes or migrations to a new file system class.
- Confirm with your storage vendor and your own environment the locking and performance behavior of any shared file system.

