Moodle security hardening

A practical plan for hardening a self-hosted Moodle site, covering the web root, PHP, administrator access, roles, plugins, uploads and security patching, and what to hand over.

On this page

Moodle security hardening starts with the web root and the admin account

Hardening a Moodle site means reducing what an attacker can reach, what they can do once inside, and how quickly you can close a gap when a security release ships. A Moodle site that holds learner records, staff data and grades needs that work before it faces a security review, and the default install is not the hardened install. The installer gets the application running; it does not decide which directories are web-accessible, how PHP behaves, who holds administrator rights, or which plugins your organization trusts. Those decisions are yours, and they span the web server, PHP, Moodle's own settings and the routine your team follows after go-live. None of it is a one-time task.

Start with the web root. From Moodle 5.1, the web server document root must point to the new /public directory rather than the main Moodle folder, and the release notes warn that otherwise the site may show directory listings or errors. Confirm this in the virtual host or server block, then check that code, configuration and moodledata are not reachable by URL. Pair it with the PHP settings your Moodle version requires: confirm the 64-bit PHP release against the Moodle 5.1 release notes or the release notes for your target version, and review disable_functions, expose_php and upload limits in the environment you actually run.

The administrator account is the highest-value target on the site. Create named administrator accounts, keep the number small, and enforce MFA through your identity provider or an approved Moodle authentication method, confirming first what your chosen auth plugin supports. Separate day-to-day teaching accounts from administrative ones, and record who holds site administrator rights, since the roles and capabilities section covers how to narrow them. Ask your team to name the single person who approves any change to administrator access, and to review that list on a fixed schedule, because accounts that outlive their owners are a common finding in reviews.

Which Moodle components a hardening review touches

A hardening review of Moodle touches the web server, PHP, the database, the data directory, authentication and the installed plugins. Each area has its own settings and failure modes, so a review should check them together rather than one at a time.

Web server and document root

The web server decides what the public can reach. From Moodle 5.1, the document root must point to the /public directory, not the main Moodle folder. If it does not, the site can expose directory listings or show errors. Check that only the public folder is served, that PHP files outside it are not reachable and that the server configuration matches the version you run.

Moodle 5.1 release notes

PHP configuration

PHP settings control how uploads, sessions and errors behave. Review display_errors, expose_php, upload_max_filesize and post_max_size, and confirm the PHP version is still in security support. Moodle 5.1 requires 64-bit PHP 8.2 or later, so an older runtime is both a security gap and a blocker for upgrades.

Moodle 5.1 requirements

Database account

The database account used by Moodle should hold only the privileges the application needs for normal operation and installation or upgrades. Keep administrative credentials out of the web-facing configuration, restrict network access to the database host and confirm backups are encrypted and access-controlled. Ask your administrator which account runs upgrades and who can read the configuration file.

The moodledata directory

The moodledata directory stores uploaded files, caches and session data outside the code tree. It must not be reachable from the web, and file permissions should let only the web server and Moodle process write to it. Review where it sits on disk, how it is backed up and whether any file storage plugin moves content elsewhere.

Authentication plugins

Moodle core ships authentication plugins for manual accounts, email self-registration, external database, LDAP, LTI, OAuth 2, Shibboleth and web services. Disable every method you do not use, because each one is an entry point. SAML 2.0 comes from the auth_saml2 plugin, not from core. The core list comes from the public/auth directory of the Moodle repository, so check it against your release.

Core auth plugins

The installed plugin set

Moodle documents more than 50 plugin types, and every installed plugin runs code with access to your data. Inventory each plugin, its source, its version and its maintenance status, and remove anything unused. Check each one for compatibility with your Moodle release before and after upgrades, since unmaintained plugins are a common source of unpatched exposure.

Moodle plugin types

Hardening decisions: document root, MFA route and plugin policy

The first decision is how the web server maps to the Moodle code. From Moodle 5.1, the document root should point to the new /public directory rather than the main Moodle folder, and the release notes warn that otherwise the site may show directory listings or errors. On a 5.1 or later site, this is the layout you should use, because it keeps code, configuration and internal files outside the directly served path. On an older site, you may be on the legacy layout and need extra web server rules to block access to non-public paths, which are easier to get wrong and harder to audit.

  • Pointing at /public on 5.1 or later: The web server serves only the public tree, which reduces the chance that internal files are reachable by URL.
  • Legacy layout before 5.1: Works on older releases, but you must write and test deny rules for internal directories yourself.
  • Upgrade effort: Moving to /public changes the web server configuration, so every upgrade to 5.1 needs a change window and a test of the vhost.
  • Dependence on your web tier: Rules live in Nginx or Apache config, so they must be kept in version control and reviewed with each release.
  • Verification: Confirm that internal paths return errors and that directory listings are off after each change.

Before you choose, confirm the exact document root behavior for your web server and your current Moodle version with the Moodle 5.1 release notes.

How to harden a Moodle site in sequence

This sequence takes a Moodle site from an unverified install to a documented baseline: a supported version, a locked-down web and PHP layer, controlled administrator access, reviewed roles, a plugin and upload policy, and a routine for applying security releases. Each step closes with a check that the reviewer can repeat.

  1. Confirm the supported version and platform versions

    Start by recording the Moodle version, PHP version, database engine and web server in use, then compare them with the release notes for the target branch. Moodle 5.1 requires 64-bit PHP 8.2 or later, and 5.3 requires PHP 8.3 or later, with specific PostgreSQL, MySQL, MariaDB or SQL Server versions for each release. Confirm the site is on a branch that still receives security support, using the Moodle releases page, and confirm the owner who will act on security notices. The step is done when the team holds a written version inventory with a security support end date for each component.

  2. Point the web server document root at public

    On Moodle 5.1 or later, the web server document root must point to the /public directory rather than the main Moodle folder. The web server administrator makes this change and removes any alias or rule that exposes the code directory directly. Check the result from outside the network: a request to a non-public path such as a PHP file under the code directory, or a directory listing request, should return a denial or a not-found response, and the Moodle front page should load normally. Record the test requests and their responses in the hardening log.

  3. Lock down PHP settings and file permissions

    The platform administrator sets PHP options such as disabling dangerous functions that Moodle does not need, limiting upload and post sizes to the agreed policy, and turning off display of errors to end users. Code files should be owned by a deployment account and readable but not writable by the web server user, with only the data and cache paths writable. Confirm the settings with a PHP information check run from the admin console or a controlled test page that is removed afterward. The step is complete when the effective settings match the written configuration and the web server user cannot modify application code.

  4. Separate moodledata from the web root

    The moodledata directory holds uploaded files, backups and caches, and it must sit outside the web-accessible tree. The server administrator moves it if needed and sets the path in the Moodle configuration file. Then request a file from moodledata directly through a browser; the response should be a denial or a not-found result. Also confirm that backups and exports are stored in a location with restricted access and that their permissions match the sensitivity of the course data they contain.

  5. Restrict administrator accounts and enforce MFA

    Reduce the number of site administrators to named individuals with a documented need, and create a separate account for administrative work so day-to-day accounts do not carry elevated rights. Route authentication for administrators through the organization's identity provider, and enforce multi-factor authentication there, since Moodle's own options depend on the chosen authentication plugin. Confirm the result by signing in with a test administrator account that lacks MFA and verifying that access is refused. Remove any default or shared administrator accounts and record the list of remaining holders.

  6. Review roles and capabilities

    Review the role model against the course and category structure, starting with the system-level roles such as manager and administrator, then the category and course roles given to teachers and support staff. Remove capabilities that are assigned by default but not needed, and avoid granting site-wide roles where a category role is enough. Use the permission check tools in Moodle to confirm what a sample user in each role can actually do, and check that teacher roles cannot change site configuration. The step ends when a reviewed matrix of roles and sample user tests matches the approved access design.

  7. Set the plugin and upload policy

    Inventory every installed plugin, its source, its maintainer and its support status for the Moodle version in use, and remove any that are unused or unmaintained. Define an approval process for new plugins that includes code review, a test install in a non-production copy and a check of the file types the plugin accepts. Set Moodle's allowed file types and maximum upload sizes to the policy, then upload a file of a disallowed type as a test user and confirm it is rejected. Keep the approved plugin list under version control so later changes are visible.

  8. Establish a routine for security releases

    Subscribe the responsible team to Moodle's release announcements, and set a written routine for applying minor point releases and security fixes on a regular schedule, with a test copy of the site used to validate each update before production. Moodle ships minor releases every two months, so the routine should be built around that cadence. Record each applied release, the date it was tested and the date it reached production. The routine is in place when the next scheduled release has a named owner, a test environment and a rollback plan, and the last applied release is recorded in the hardening log.

How roles, capabilities and plugins create hidden exposure

Roles and plugins are where a Moodle site most often loses control without anyone noticing. Moodle's capability model is built from roles, and those roles can be widened in several places at once: site-level role assignments, category-level role assignments in course categories, course-level enrolments, and custom roles that an administrator copied from a built-in role and edited. Each of these can grant a capability that the site owner never intended. Start with a written inventory. List every account with the site administrator role, every role assignment at category level, and every custom role with its capability overrides. Ask for each entry who approved it and why it still exists. Expect the list to be longer than the team's mental model, particularly on sites that have run for several years through staff changes.

Plugins widen exposure in a different way. Moodle documents more than 50 plugin types, and many of them add capabilities the core does not have: activity modules that accept content from users, blocks that render data on pages, local plugins that add arbitrary pages and controllers, report and admin tool plugins that read or change site data, enrolment plugins that grant access, and web service functions that expose data to external systems. A plugin installed for a single department can therefore touch user records, grades or authentication. Before installing anything, review what it registers, including its web service functions and any capabilities it defines in its access file, and confirm which administrators can enable it.

Vet each plugin against a written checklist before it reaches production. Record the maintainer and whether the maintainer is an individual, a company or the Moodle HQ team. Record the source: the Moodle plugins directory or a named repository, with the exact version and a checksum where one is published. Confirm compatibility with the target release by checking the plugin's declared supported versions against your planned Moodle version, since a plugin that works on your current release may not be supported on the one you are moving to. Confirm the code is licensed under GPL, because Moodle core is GPL-3.0 and you need to know the terms that apply to what you run and distribute. Finally, record who can approve updates and who removes the plugin when it is abandoned. Ask your implementation partner to apply the same checklist to any plugin they propose.

What drives hardening effort on a Moodle site

This table compares the factors that raise or lower the work needed to harden a self-hosted Moodle site, with the reason each one adds effort and how to keep it manageable. Read it before scoping, because most of the effort comes from the size of the estate, not from the core platform itself. The main takeaway is that every extra plugin, identity source, environment or custom component adds review and retest work that should be named in the written scope.

DriverWhy it raises effortHow to keep it down
Number of installed pluginsEach plugin adds code to review, its own update cycle, and permissions to check. Contributed plugins may lag behind a new Moodle release.Inventory plugins before scoping, remove unused ones, and prefer maintained plugins with a current version for your release.
Custom codeCustom plugins and theme changes need security review, input handling checks and retesting after every upgrade.Limit custom code to needed gaps, follow core APIs, and keep a documented review step for each change.
Number of identity sources and SSO flowsEach sign-in path (manual, LDAP, OAuth 2, SAML 2.0 through a plugin, Shibboleth) needs its own configuration, MFA position and account-linking checks.Confirm which login paths are required and disable the others, such as self-registration, where the business does not need them.
Role and category complexityCustom roles, overrides at many category levels and delegated administration increase the number of capabilities to check for unintended access.Start from core roles, document each custom role's purpose, and test access with sample accounts for each role.
Number of environments (development, test, production)Each environment needs matching hardening, separate secrets and a way to prove that production matches what was tested.Keep environments built from the same configuration and limit production-only changes to a tracked list.
Upload types and file sizesAccepted file types, size limits, antivirus scanning and the handling of uploaded content in course areas each need a decision and a test.Restrict file types to those teaching needs require, set size limits per use, and test scanning and download behaviour.
Existing server estateLegacy web servers, shared hosts, older PHP or database versions and manual configuration drift take time to bring into a documented baseline.Record the current stack, then rebuild the web server, PHP and database settings from a single reviewed configuration.
Compliance evidence requiredAssessors expect documented controls, configuration records, access reviews and logs that show each control works, which adds collection and writing work.Agree the evidence list early, map it to each hardening control, and generate it from the running configuration where possible.

How a hardened Moodle request path is layered

The request starts with the learner or administrator, who signs in through the identity provider, where MFA and SSO are enforced before any session reaches Moodle. The web server then serves only the /public directory, so Moodle core and approved plugins sit behind it and are never listed or browsed directly. PHP runs with restricted settings, and Moodle talks to the database, while moodledata stays outside the web root. Check that the document root is /public, that moodledata is not reachable by URL, and that admin access sits on its own trust boundary.

Trust boundaries and hand-offs in a hardened Moodle request path.

Security controls for administrator accounts, uploads and secrets

Most Moodle compromises start with an over-privileged account, an upload that should never have been accepted, or a credential sitting where a browser can read it. The controls below close those paths. Confirm each setting against the exact Moodle version you run, because menu names and defaults change between releases.

Separate admin accounts and enforce MFA

Give each administrator a personal account and a second account for routine teaching or course work, so day-to-day browsing never runs with site-level rights. Require multi-factor authentication for every account holding administrative capabilities, ideally through the identity provider rather than Moodle alone. Check the MFA and login settings in your version, and confirm that break-glass access is documented and tested.

Restrict the site administrator role

The site administrator role bypasses most capability checks, so keep the list short and reviewed. Audit who holds it at site level, remove it from accounts that only need course or category management, and use delegated roles for everything else. Run a recurring export of role assignments and treat any unexpected change as an incident.

Set upload type and size limits

Restrict which file types can be uploaded to each activity and repository, and set the maximum upload size to what courses actually need. Review which plugins accept files and whether any of them store content in web-readable locations. Test each limit with a disallowed file type and an oversized file, and confirm the web server and PHP limits match the Moodle setting.

Keep secrets out of web-readable files

Database passwords, SSO client secrets and API tokens belong in config.php or environment settings outside the web root, with restrictive file permissions readable only by the web server user. Confirm that config.php is not served by the web server and that backups and version control exclude it. Rotate any secret that has ever been committed, pasted into a ticket or shared in chat.

Use least-privilege database accounts

The Moodle database user needs rights to its own schema and nothing else, with no server-wide or administrative privileges. Keep separate accounts for routine application access and for upgrades, where the upgrade account is used only during maintenance windows. Confirm the grants against the database versions your Moodle release supports, since the supported engines differ by release.

Log administrative changes

Enable and review the Moodle logs for changes to roles, authentication, plugins and site configuration, and forward them to a system your security team monitors. Logs stored only on the Moodle server are easy to alter or lose during an incident. Test that a change to a role or an admin setting produces a record, and set a retention period that matches your policy.

Moodle 5.1 notes

How to test that the hardening holds and fails safely

Verification comes down to attacking your own site from the outside and confirming each control fails closed. Start with the web tier: request the site root and a few guessed paths such as /admin, /lib and /public and confirm there are no directory listings or stack traces. Since Moodle 5.1 the document root must point to the /public directory, so confirm the web server serves nothing from the main Moodle folder. Then request config.php, files under moodledata and backup files directly from the browser and from an unauthenticated client. Every request should return a denial or a 404, and the test should be repeated after each web server or PHP change, because a misplaced alias can expose these paths without any Moodle error.

Next, test authorization and authentication as a user, not as an administrator. Sign in with a non-admin account and attempt to reach administration pages, site-level report builders, other users' profiles and course settings for courses the account does not manage. Then test login with MFA enforced for administrator and manager roles, and with the identity provider deliberately unavailable or its certificate removed from the test configuration. The expected result is that login stops and does not fall back to a local password for privileged accounts. Confirm which authentication methods remain enabled, because an unused manual or email self-registration path can bypass the SSO control you intended.

Test uploads and plugins last. Upload a file type the site policy disallows, an oversized file and a file with a permitted extension but unexpected content, and confirm each is rejected and logged. Run a plugin inventory against the release you are running, comparing installed plugin names and versions with the versions your vendor or review process approved, and flag anything unknown or unmaintained for the next review. Confirm which plugin types are present, since most have upgrade and security implications. Record every test with its date, tester, expected result, actual result and evidence (screenshot, log line or command output), and keep the set for the reviewer so the next release can be retested against the same list.

What to monitor, patch and document after hardening

What should I monitor in Moodle after hardening?

Monitor login activity, role and capability changes, and plugin installs or updates, because these are the events that show whether your hardening still holds. Route Moodle's logs to a central system your security team reviews, and alert on failed login spikes, administrator logins from unexpected locations, and any new role assignment at site level. Ask your team to confirm which log sources your hosting platform keeps, how long they are retained, and who receives alerts outside office hours. Retention periods and tooling depend on your own policies and infrastructure.

How do I track role changes and plugin installs in Moodle?

Review the site's logs for role assignments and capability overrides, and check the list of installed plugins against the approved baseline at regular intervals. Plugin installs should happen only through a change process that records who approved the plugin, its version and its source. Confirm with your administrators whether plugin installation through the web interface is disabled on production, because that setting belongs to your configuration baseline and should be checked after every upgrade.

How often should I back up the Moodle database and moodledata?

Back up the database and the moodledata directory together, on a schedule your recovery requirements set, and test restores on a regular basis. The two must match: restoring a database without the matching files leaves course content pointing at missing data. Your recovery time and recovery point targets, and the retention length, should come from your business owners, not from a default. Ask your hosting or operations team to confirm where backups are stored, whether they are encrypted, and whether a copy sits outside the primary environment.

How should we apply Moodle security releases?

Plan to apply minor point releases as they arrive, because security fixes are delivered there. Moodle's minor releases fall in February, April, June, August, October and December, and major releases arrive in April and October. Test each update on a staging copy that mirrors production, including your plugins and theme, before scheduling the production change. Keep a written rollback plan with a fresh database and moodledata backup taken immediately before the update.

How do I know when my Moodle version stops getting security fixes?

Track the security support end date for the version you run and plan the next upgrade well before it. Moodle publishes these dates on its releases page: for example, Moodle 5.1 has security support until 19 April 2027, Moodle 5.2 until 4 October 2027, and Moodle 4.5 as a long-term support release until 4 October 2027. Put those dates in your operations calendar and check them against your running version each quarter. Confirm the current dates on the releases page before you plan, since they can change.

What configuration baseline should we document after hardening?

Document every setting that affects security so an auditor or a new administrator can see what the site is meant to look like. Include the web server document root, PHP settings, database version, authentication methods and MFA policy, administrator accounts, role and capability overrides, the approved plugin list with versions, file upload restrictions, and backup and patch procedures. Store the baseline under version control, record the date and owner of each change, and compare the live site against it after every upgrade. Your compliance team should confirm which evidence they need to keep.

Can DeployOpen help us run these operations after hardening?

DeployOpen can support Moodle environments after go-live, including upgrades, plugin compatibility checks and continued maintenance, and these are available as retainers. The scope of monitoring, patching and documentation is agreed in writing before work starts, and the exact responsibilities split depends on whether your team or DeployOpen operates each control. Ask for a written responsibility matrix in any proposal so you know who owns each item in this list.

How DeployOpen scopes and hands over Moodle hardening

DeployOpen runs Moodle hardening as fixed-scope work agreed in writing before it starts, carried out inside your own infrastructure, whether that is your cloud account, a data center or an air-gapped network. The written scope names the Moodle sites and environments covered, the web server and PHP hosts, the database, the authentication methods in use, the plugins to be reviewed, and the deliverables. Before any change is made, the scoping review confirms which Moodle version is running and which release is the target, because security support windows differ. For example, Moodle 5.1 has security support until 19 April 2027, while Moodle 5.2 has security support until 4 October 2027. Your team should confirm the version and its support end date with its own records and the Moodle releases page before scoping begins.

The baseline comes next. DeployOpen records the current state of the document root, the PHP settings and disabled functions, the administrator accounts and MFA status, role assignments and overridden capabilities, the installed plugins and their sources, and the file upload rules. The configuration changes are then made in a change window your team approves, and each change is logged against the baseline. Verification follows: DeployOpen retests the changed controls, checks that moodledata is not reachable from the web, confirms that administrator access requires the agreed MFA path, and reviews the results with your security and platform owners. Remediation items that fall outside the scope are listed separately so they can be quoted rather than absorbed silently.

At handover you receive the configuration records, runbooks for patching and account administration, the verification results, and an evidence pack that your internal or external auditors can review. DeployOpen prepares this evidence but does does not issue audit reports, attestations or certifications; independent auditors and certification bodies do that work. A quote follows from the written scope, so ask for it to name each deliverable, each environment and the retest. Ongoing security patching of Moodle releases, periodic configuration review and continuous testing are available as retainers, which keep the hardening current as new security releases ship.

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.