Which Moodle directories must be shared across a cluster
A team running two or more Moodle web nodes behind a load balancer has to decide which directories every node must see and which can stay on each server's own disk. Getting this wrong produces symptoms that look random: uploaded course files missing on one node, caches going stale, or backups failing only when a request lands on a particular server. Moodle is self-hosted and its code is licensed under GPL-3.0, so the storage layout is your design to own and verify in your own infrastructure. This section sets the frame for the directories covered in this page: dataroot, tempdir, cachedir, backuptempdir, localcachedir and localrequestdir.
The most important split is between data that must be shared and data that is safe to keep local. dataroot holds user uploads, course files and other content that every web node must read and write consistently, so it belongs on shared storage that all nodes mount. Directories such as localcachedir and localrequestdir are built for per-node use, and the decision is whether each node gets its own copy. Before you choose, confirm in the Moodle documentation for your exact version how each setting is described and whether cachedir and tempdir are expected to be shared or local, because these defaults are not something to assume from memory.
From Moodle 5.1, the web server document root must point to the new /public directory rather than the main Moodle folder, so the same web server configuration must be applied identically on every node. Plan the mount points, ownership and permissions for each directory before the first node goes live, and test them by writing from one node and reading from another. Sites on Moodle 5.1 or later should also check the Moodle 5.1 release notes for any changes that affect where these directories sit relative to the code.
Directory options and when each storage choice fits
This table compares each Moodle directory setting by what it holds, whether web nodes must share it, and which storage types a team might choose. Read each row as a starting point, then confirm the sharing and locking behaviour against the Moodle admin documentation for your target version before you commit to a layout.
| Directory | What it holds | Shared across nodes? | Storage choices and constraints |
|---|---|---|---|
| dataroot | User uploads, course files and other persistent site data | Yes, every web and cron node must see the same content | Shared network file system or object-backed shared file system; local disk only fits a single node. Confirm file locking support with your storage vendor |
| tempdir | Short-lived working files created during requests and uploads | Usually yes if nodes exchange temporary files; confirm for your version | Shared file system for simplicity, or local disk if a node never hands temp files to another node. Confirm in the admin docs |
| cachedir | Compiled templates, language strings and other rebuildable cache files | Not required when cache stores are Redis or APCu; otherwise confirm | Local disk is often sufficient for a file-based cache per node; shared storage adds latency and locking risk |
| backuptempdir | Staging area while course and site backups are assembled | Only if the backup job runs on a different node than the one serving the admin user | Local disk on the node running backups, or a shared path if the backup job can run on any node. Confirm the path with your backup process |
| localcachedir | Node-specific cache data such as JavaScript and CSS build output | No, each node should keep its own copy | Local disk on each web node. Keep it off network storage so each node can rebuild independently |
| localrequestdir | Per-request working data that should not leak between nodes | No, must stay local to each node | Local disk only. Do not place it on shared storage, and confirm the default for your version |
| Lock factory interaction | Locks that protect cron, tasks and some file operations | Depends on the lock factory chosen for the cluster | File-based locks on NFS are a common failure point. Confirm the lock factory and its limits before choosing shared storage for dataroot |
Why dataroot is shared and most temporary paths are not
Dataroot must be shared across every web node because it holds the data that defines the site: user uploads, course files, and the files that backups and restores depend on. Any node that handles a request has to be able to read a file a different node wrote, or a student who uploads an assignment on one node will see a broken link when the next request lands on another. That is the reason dataroot sits on storage that every node mounts at the same path, and it is the one directory where the sharing decision is not optional. The practical check is simple: upload a file through one node, then open it through each of the others, and confirm the same path resolves everywhere.
Most of the other paths carry data that is rebuilt on demand or lasts only for one request, so they gain little from being shared and can cost a lot. Cache entries, compiled templates and temporary files are disposable, and if every node writes them to one network location, nodes compete for the same file locks and see each other's partial writes. A node that reads a half-written cache file or a temp file another node is about to delete fails in ways that are hard to reproduce. Keeping these paths local to each node means each node reads and writes its own copy, so contention drops and a node never serves stale content written by a peer. The cost is that each node may rebuild data a peer already has, which is why the cache layer and the file-serving design belong in the same review.
Before you decide, list every path in your configuration and mark it as persistent or disposable, then confirm the answer with your Moodle version's documentation and your storage vendor, because the defaults and the expected locations for localcachedir, localrequestdir and backuptempdir differ between releases and deployments. Plan for the failure mode that matters most: a path that looks local but is actually on shared storage, or a shared path that a node can write to but not read back consistently. Both produce errors that appear intermittently and only under load.
How to configure shared and local paths on each web node
This sequence turns a single-server Moodle paths setup into a cluster layout where dataroot is shared, cache and temp paths are node-local, and every web node resolves the same directories the same way. The result is a checked configuration that survives a node restart and a backup run.
Inventory the paths currently set in config.php
Open config.php on the existing site and record every explicit path setting: dataroot, tempdir, cachedir, backuptempdir, localcachedir and localrequestdir, along with the current document root in the web server. Note which values are set explicitly and which fall back to defaults under dataroot. Confirm the list against the path settings in your own Moodle version's documentation, since defaults and available settings can change between releases. The step is done when you have a written table of current values, each with an owner and a target location in the new layout.
Choose shared storage for dataroot
Decide which storage technology will hold dataroot, the directory where Moodle keeps uploaded files, course backups and other persistent data. The storage must be mounted at the same path on every web node and must support the locking and file operations Moodle relies on, so ask your storage team and your Moodle partner to confirm the protocol, latency and locking behavior before you commit. Record the choice, the mount options and the owner of the storage. The step is done when a written storage decision names the mount path and has been reviewed by the people who will run it.
Set node-local paths for cache and temp directories
Point cachedir, tempdir, localcachedir and localrequestdir at directories on each node's local disk, and keep backuptempdir local as well unless your backup process needs a shared scratch area. Local paths avoid sending high-frequency cache writes across the network to shared storage. Use the same relative layout on every node so that scripts and monitoring treat the paths identically. The step is done when config.php on each node lists these paths and the directories exist locally with the correct owner.
Mount and permission each path identically on every node
Mount the shared dataroot at the same absolute path on every web node, and create the local directories with the same owner, group and mode everywhere. Mismatched UIDs or GIDs between nodes are a common cause of files that one node cannot read or write. Compare the output of a directory listing with numeric owners on each node. The step is done when the listing matches across all nodes and the web server user can write to every directory it needs.
Point the web server document root at /public on 5.1 or later
On Moodle 5.1 and later, set the web server document root to the new public directory inside the Moodle code folder, not the main folder. The release notes warn that otherwise the site may show directory listings or errors. Apply the change on every node and reload the web server. The step is done when a request to the site returns the Moodle login page and a request for a directory path inside the code tree is refused rather than listed.
Verify with a test upload
Log in as a site administrator on one node, upload a small test file to a course or to a private file area, then open the same file from a second node. The file should download without error and its stored location should sit under the shared dataroot. Repeat from the other direction. The step is done when the file is retrievable from every node and the test file appears on the shared storage path with the expected owner.
Verify with a cache write and a backup run
Load a page that writes to the application cache, then confirm on each node that the cache files appear under the local cachedir and not under dataroot. Trigger a manual course backup and confirm that the temporary files are created in the configured backuptempdir and that the backup file lands in the expected location on shared storage. Review the Moodle logs for path or permission warnings. The step is done when cache writes stay local, the backup completes on every node that runs it, and no path errors remain in the logs.
Storage choices for shared and local paths by environment
On-premises clusters most often share dataroot and sometimes tempdir over NFS because it is simple to present to every web node. The trade-off is that every file read and write crosses the network, so latency shows up on pages that touch many small files, and a slow or unavailable NFS server affects every node at once.
- Latency: Keep the shared path for content that is read or written rarely, and avoid placing
cachedirorlocalcachediron NFS, since Moodle reads these often. - Locking: NFS lock behaviour depends on the protocol version, mount options and server configuration. Confirm that file locks work as Moodle expects before choosing the file lock factory, since this is a common source of cron problems.
- Permissions: Ensure every web node and the cron host map the same UID and GID to the export, and that the web server user can write
datarootbut the export is not world-writable. - Operations: Mount options such as hard versus soft mounts change what happens during a network interruption. Ask the storage team which option they run and what they will do during an outage.
- Confirm: Ask the storage vendor or platform team for the NFS version, mount options, lock manager behaviour, and backup and snapshot consistency for the export.
Test the shared path under realistic upload and cron load in a staging cluster before production, and record the mount options in your configuration management.
In cloud environments, teams often choose between block volumes attached to a single node, managed network file services, or object storage fronted by a file gateway. Block volumes are fast but generally cannot be mounted read-write by several web nodes at once, so they suit local paths rather than shared ones. Managed file services can be shared across nodes but differ in latency and locking from local disks.
- Latency: Managed file services usually add network round trips per operation. Keep
localcachedirandlocalrequestdiron each node's local disk so frequent reads stay fast. - Locking: Some managed file services support POSIX-style locks and others do not. Confirm lock support with the provider before relying on file-based locks in a cluster.
- Permissions: Cloud file services may apply their own access policies on top of POSIX modes. Check that the web user, cron user and backup job can all read and write the paths they need.
- Operations: Snapshot and backup features differ by service, and some do not give consistent snapshots of an active directory. Ask how the provider handles this for the chosen service.
- Confirm: Ask the provider for the protocol, the supported lock semantics, the consistency and durability model, and the cost model for throughput and requests.
Do not assume that a managed service behaves like a local disk. Measure upload, restore and cron timings on the chosen service.
On Kubernetes, shared paths are usually backed by PersistentVolumeClaims. The access mode determines whether several Moodle pods can mount the same volume. Local paths can often be ephemeral per pod, but caches and request files still need to be placed deliberately so they are not lost or shared accidentally.
- Access modes: Shared
datarootrequires a volume that supports ReadWriteMany. Confirm which storage class in your cluster provides it, since ReadWriteOnce volumes cannot be shared across nodes. - Latency: Keep
localcachedirandlocalrequestdirinemptyDiror node-local storage where possible, and treat them as disposable. Rebuilding caches after a restart is usually acceptable, but confirm this with your own load tests. - Permissions: Container user IDs,
fsGroupand the storage driver's ownership handling must agree, or pods fail to write todatarootafter a reschedule. - Operations: Volume expansion, snapshot classes and backup tooling vary by driver. Confirm that backups capture
datarootconsistently and that restores have been tested. - Confirm: Ask the platform team which storage class provides ReadWriteMany, its locking behaviour, its snapshot support, and how it behaves during node drains and zone failures.
Write these choices into the Helm values or manifests so the same layout survives rescheduling and upgrades.
Security and operational risks of shared directories
Shared directories hold uploaded files, temporary data and backups, so a mistake in any one of them exposes content that the database would otherwise protect. The cards below pair each risk with a control and a check you can run before go-live. Where the risk is about web exposure or server hardening, the Moodle security hardening pages carry the detailed settings.
Over-broad permissions on dataroot
Dataroot holds uploaded course files, user files and backups, and every web node must be able to read and write it. Teams often grant broad permissions to make a mount work, which lets any local account or service on the host read learner data. Give the web server user ownership, restrict group and other access, and confirm that the CLI and cron user is the same account the web nodes run as. Check the result with a listing of the directory tree after a fresh install.
Dataroot or cache paths served by the web server
Moodle's document root should point to the public directory, but a misconfigured vhost or an alias can still expose dataroot, cachedir or tempdir over HTTP. Files in those paths may be served without Moodle's access checks, so a guessed or leaked path can reveal private content. Test each path from outside the cluster and confirm that a direct request returns a denial, not a file. Pair this check with the file-serving configuration described in the sibling topic on X-Sendfile and X-Accel-Redirect.
Backup handling of shared paths
Backups of dataroot can contain every uploaded file and backup archive on the site, and backuptempdir may hold partial archives while a backup runs. If those paths sit on a network share with broad read access, a backup copy can leak outside the controls that protect the live site. Decide where backup archives are written, who can read them, how long they are kept, and whether they are encrypted at rest. Record these decisions in the operations runbook so a restore does not reintroduce an unsafe location.
Stale and leaked temp files
Tempdir and localrequestdir collect intermediate files, and some are written with contents from user uploads or generated reports. If scheduled cleanup does not run on every node, old files accumulate and remain readable by anyone with access to the directory. Check that the cleanup task runs, that the temp path is not world-readable, and that file ages are monitored with the same alerts as disk use. Keep temp paths local where possible so a single node holds its own leftovers, not a shared copy.
Mount failures during node replacement
When a web node is replaced, its shared mount must come up with the same options and identity before Moodle starts serving requests. A missing or stale mount can cause Moodle to write into an empty local path, which looks healthy but splits uploads across nodes. Automate the mount in the build, fail the health check when dataroot is not mounted, and test a replacement node in staging before a live event. Confirm which settings your storage team uses for mount retries and timeouts.
Access logging on shared storage
Shared file systems can log access at the storage layer, and those logs may record file names that reveal course or user details. Retention and access to these logs often differ from the Moodle logs your compliance team reviews. Ask the storage team whether access logging is enabled, where logs are kept, who can read them, and how long they are retained. Align the answers with the Moodle logging and privacy decisions so that no sensitive path or name is written to a place with weaker controls.
Questions teams ask before changing Moodle directories
Is a single NFS export enough for a Moodle cluster?
Often it works for the shared directories, but it is not enough on its own. A single NFS export gives every web node the same dataroot, so uploads and course files are visible everywhere. The questions that decide whether it holds are how many nodes write to the share at once, how much file churn your backup and cron jobs create, and how the share behaves under failure. Ask your storage team to test file locking, latency under peak uploads and what happens when the export is unavailable. Keep the localcachedir and localrequestdir on local disk on each node, because those directories are written constantly and do not need to be shared.
What makes moving from one server to a cluster take longer?
The effort depends mainly on how many directories you must split, how much data sits in dataroot, and how much your current setup depends on local paths. Teams that have hard-coded paths in web server configuration, custom plugins or scheduled scripts usually spend more time than teams that only change config.php. Other drivers are the storage product you choose, the number of environments you must keep in step (test, staging and production), and how much you must prove to a change board before a cutover. Ask any partner for a written list of the directories, paths and jobs they will touch before they quote.
Can our own team change the Moodle directories without a partner?
Yes, if your team has Linux administration, web server and storage skills and time to test. The configuration changes themselves are small, but the risk sits in the surrounding work: file permissions for the web user, consistent UIDs across nodes, backup and restore of the shared data, and checks that cron and cache purges do not fight each other. A partner is most useful when you need a documented test plan, a rehearsed cutover and a runbook your operations staff can follow. Ask your team to list which of these skills it has in-house before deciding.
What does the work need from our infrastructure and security teams?
Infrastructure teams need to provide the shared storage, network paths between nodes, and capacity planning for file growth. Security teams need to review who can mount the share, how file permissions are set, whether data is encrypted at rest and in transit, and how access is logged. Both teams should agree on backup scope and restore tests for dataroot before go-live. Ask them to confirm storage performance and access controls in writing, because the Moodle configuration cannot compensate for a share that is slow or too widely exposed.
What recurs after the directories are moved to shared storage?
Some costs are one-time, such as the migration, testing and cutover. Others recur. Storage capacity grows with uploads and backups, the share needs monitoring and patching, and each Moodle upgrade should be checked against the directory layout. Your team also needs to keep node configuration consistent when servers are added or replaced. Ask for a list of recurring tasks, who owns each one and how often the restore test should run. Moodle itself ships minor point releases in February, April, June, August, October and December, so plan time for regular patching on that rhythm.
Which directories must be shared and which should stay local?
Share dataroot and the data that must be the same on every node, such as user files and course content. Keep localcachedir and localrequestdir local to each node because they are written often and must not be shared. Decide tempdir, cachedir and backuptempdir case by case, based on how your storage performs and whether a lost file would cause a failure. The main trade-off is consistency against speed. Confirm the exact settings for your Moodle version in the official documentation before you change anything.
Does moving directories change our Moodle upgrade plan?
It can. Upgrades must be tested on a copy of the cluster that matches production, including the shared storage layout. Moodle 5.1 requires the web server document root to point to the /public directory, so check that your storage paths and web server rules are updated together. Read the release notes for the version you plan to run before scheduling any cutover, and confirm the minimum starting version for your upgrade path.
How shared and local paths sit across Moodle web nodes
The diagram starts at the load balancer, which sends each request to one of several web nodes. Every node keeps its own localcachedir, localrequestdir and tempdir on local disk, so hot data and scratch files never cross the network. The shared storage tier holds dataroot and backuptempdir, and every node reads and writes the same database. Check that the shared mount is the only path that crosses the trust boundary between the web tier and storage, and that no node-local path is expected by another node.
Shared paths cross the storage boundary, while cache, request and temp paths stay on each node.
How DeployOpen scopes and delivers a shared directory design
DeployOpen treats the directory layout as a written design before any node is cloned. The work covers which Moodle paths sit on shared storage, which stay local to each web node, and how those choices are tested and handed to your operations team.
How we scope
- Inventory every Moodle path setting on your current site, including dataroot, tempdir, cachedir, backuptempdir, localcachedir and localrequestdir.
- Record the number of web nodes, the storage platform you run and the file types your courses and backups generate.
- Agree the written scope, deliverables and timeline before work starts, with the storage and network changes you own listed explicitly.
How we build
- Map each directory to shared or local storage and document the reason for every placement against your load and failure requirements.
- Configure the shared mounts, permissions and Moodle config settings in a staging cluster that mirrors production node count.
- Test node failover, concurrent uploads, backup and restore, and cron behavior across nodes before any cutover.
How we hand over
- Deliver a directory design document with the path map, mount options, permission model and the reasoning behind each decision.
- Provide runbooks for adding a web node, rotating storage, clearing temporary data and restoring dataroot from backup.
- Walk your platform and Moodle administrators through the configuration and the verification checks they should repeat after changes.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers, so the layout can be revisited with each Moodle release.
- Retest the directory design after storage changes, Moodle upgrades or additions to the web tier.
- Confirm with your storage vendor the mount, locking and latency behavior your chosen platform supports before relying on it.

