Managing Moodle settings as code

Moodle settings drift when administrators change production by hand and nobody can reproduce the change in test. This page explains how to manage Moodle settings as code with forced config.php values, admin presets and the config changes report, and where each method stops.

On this page

Why Moodle settings as code matters before the next upgrade

Managing Moodle settings as code means keeping the administrative configuration of a Moodle site (the site settings, plugin settings and feature switches that control behavior) in a form you can version, compare, copy and reapply, so that test and production start from the same known state. A common failure looks like this: an administrator changes a setting in production during an incident, forgets to record it, and months later cannot explain why test behaves differently or why an upgrade rollout changes behavior. Moodle offers three built-in mechanisms for this: forced settings in config.php, which lock specific values so they cannot be changed in the web interface; admin presets, which export and import a set of admin settings as a file; and the config changes report (report_configlog), which records who changed which setting and when.

Settings drift between environments for ordinary reasons. Test and production are configured by different people at different times, plugins add settings after install, and emergency fixes are made directly in the web interface where nobody writes them down. Each change may look harmless on its own, but the sum makes test a poor predictor of production, and that gap tends to surface during a major version move, when the release notes and your own tests assume a configuration you cannot reproduce. Before the next upgrade, ask your team to list which settings are forced in config.php, which are maintained through presets, and which are changed only in the interface, and to confirm where the config changes report is retained and who reviews it.

This practice does not replace backups or change control. A preset or a forced setting restores configuration, not course content, user data, moodledata or the database, so a whole-site backup and tested restore remain necessary. Likewise, recording a change in the config changes report shows what happened but does not approve it. Decide in advance who may change production settings, how changes are requested and tested in a non-production environment, and how the record of each change is kept. Confirm these details against the documentation for the Moodle version you run, because the available tooling and screens differ between releases.

How config.php, admin presets and the changes report differ

Forced settings are values written into the site's config.php file, which Moodle reads on every request before the database is consulted. A forced value overrides whatever an administrator sets in the web interface, and the matching field in the admin screen is locked so the change cannot be made there. The value lives in the file system, not in the database, so it survives a database restore and it travels with the code deployment. Not every setting can be forced, and the list of what is available depends on the Moodle version, so confirm each key against the documentation for your release before you rely on it.

  • What it sets: Site-wide values such as paths, debugging behavior, and selected admin settings that you want to stop being changed from the browser.
  • Where it is stored: In config.php on the web server, under version control if your team manages it that way.
  • What it cannot reach: Settings that Moodle does not expose for forcing, and anything that belongs to a course, a user or a plugin's own data tables.
  • Who should edit it: Platform engineers through the normal change process, with the security team reviewing any change that affects authentication or logging.
  • How it appears in review: As a file diff in the deployment repository, which reviewers can read line by line.

Check that each forced key is still honored after an upgrade and that the locked fields are visible to administrators who need to understand why a value cannot be changed.

Which configuration method fits each kind of setting

This table compares four ways to set Moodle configuration: forced settings in config.php, admin presets, manual changes logged by the config changes report, and external deployment tooling. Read each row for what the method manages, when it fits and its main trade-off. Confirm which settings each method can reach in your target Moodle version before you choose.

MethodWhat it managesWhen it fitsMain trade-off
Forced settings in config.phpSite-wide values that Moodle reads at startup and that administrators cannot change in the web interface, such as database, path and selected behavior settingsValues that must never drift between environments or that security requirements say should be lockedChanges need file access and a deployment, and a wrong value can stop the site from loading
Admin presetsExported and imported bundles of selected admin settings, which can cover plugin and site configuration that the preset tool supportsRepeatable setup of a new environment or a known set of settings copied from a reference siteCoverage depends on what the preset tool exports, so confirm each setting you need is included in your version
Manual changes in the admin interfaceAny setting an administrator can edit in the web interface, with changes recorded by the config changes reportExploratory changes, one-off fixes and settings that have no code or preset path yetChanges are hard to repeat in other environments unless someone copies them by hand and records the reason
External deployment toolingSettings written by scripts or pipelines during a release, using Moodle's command line or database tools that your team maintainsLarge estates with many environments that need the same changes applied in a controlled order with reviewYour team owns the scripts, their testing and their upkeep after each Moodle upgrade

How a Moodle setting moves from test to production

A change starts as a setting made or drafted in the test site, then is captured as a config.php entry or an admin preset and committed to version control. A reviewer approves it before it reaches staging, where the config changes report shows exactly what differs from the expected state. Production receives the change only in a change window, and the report and the commit history become the evidence record. Secrets are injected from a store outside the repository at each environment, so they never pass through review or the repo.

Settings move from test to production through version control, a review gate and staging comparison.

Setting up a Moodle settings as code workflow

This sequence turns Moodle settings from undocumented admin clicks into reviewed, versioned changes that move from test to staging to production with evidence at each step. The result is a settings baseline your team can reproduce, explain to auditors and roll back.

  1. Inventory settings and assign owners

    Export a list of the settings your site depends on, grouped by area such as authentication, security, course defaults, plugins and messaging. Use the config changes report and the site's own administration pages to confirm where each value is currently set, then assign a named owner to each group who approves changes to it. Ask the owner to confirm which values matter for the business, not only which ones they remember changing. The step is done when every setting group has one owner and a written list of the values in scope.

  2. Classify environment-specific values

    Split the inventory into values that should be identical in every environment, such as security policy, enabled plugins and default course settings, and values that must differ, such as the site URL, email sender addresses, SSO metadata endpoints, external database hosts and API keys. Environment-specific values should never be promoted from test to production. Record the reason for each classification. The check is a reviewed list where every environment-specific value has a stated source, usually a secret store or an environment file, rather than a hard-coded value.

  3. Move forced settings into config.php

    For settings that must not drift, add them to config.php as forced settings so the web interface cannot override them, and keep that file under version control in your infrastructure repository. Confirm the exact config keys and their syntax against the Moodle documentation for your target release, since names and behaviour can change between versions. Keep secrets out of the file and load them from the environment or your secrets tool. The check is a code review of the change and a test on a non-production site showing the forced value appears as locked in the administration pages.

  4. Export a preset from the test site

    Once the test site reflects the intended configuration, export the relevant admin presets from it, selecting only the plugin and setting groups inventoried as shared. Review the exported file for any environment-specific values that slipped in, such as hostnames, paths or keys, and remove or template them. Store the exported file in version control with the change request that introduced it. The check is a preset file that contains only shared values and a commit that links back to the approved change.

  5. Review the diff before import

    Compare the exported preset with the currently stored configuration on staging, using the version control diff and the config changes report to see every value that will change. Have the setting owner approve each change and reject any that relate to environment-specific values. Confirm that the preset does not change anything outside the agreed scope. The check is a signed-off diff where every line maps to an inventoried setting and an owner's approval.

  6. Import into staging and verify

    Import the approved preset into staging following your documented procedure, then open the config changes report and confirm that the changes recorded match the reviewed diff, with the expected user and time stamps. Test the affected functions, such as sign-in through the identity provider, course creation defaults and enabled plugins. Log any unexpected change as a defect before continuing. The check is a staging report that matches the diff line for line, plus a short test record signed by the owner.

  7. Promote in a change window

    Schedule the production change in an agreed change window and announce it to the people who will be affected. Apply the same version-controlled preset and config.php changes used in staging, using the same procedure and the same commit, so production receives no hand edits. Keep a rollback path ready, such as the previous preset and a tested restore point. The check is that production's config changes report shows exactly the approved changes and the smoke tests pass.

  8. Record the result and keep the baseline current

    Close the change record with the commit identifier, the approver, the staging and production config changes report entries, and the test results. Update the inventory so the stored baseline matches what production now runs, and schedule periodic comparisons between the repository and each live environment to catch manual edits. The step is complete when the change record can answer who changed what, when, why and how it was verified, and when the repository and production show no unexplained differences.

Security risks when Moodle settings change outside the repository

Moodle settings live in several places: config.php, the database, admin presets and the admin interface. Each one can change without a review, and a change that looks harmless in one environment can expose secrets, weaken sign-in or lock administrators out in another. The cards below cover the risks that appear when settings move outside the repository and the control that reduces each one.

Secrets committed to version control

Database passwords, SMTP credentials, LDAP bind passwords and API tokens often end up in config.php and then in the Git history. Once committed, a secret stays in every clone and backup of the repository even after it is deleted from the current files. Keep secrets out of the repository by reading them from environment variables or a secrets manager at deploy time, and scan commits for credential patterns before they are pushed. Ask your team to confirm which of its settings files are tracked.

Unreviewed edits made directly in production

An administrator who changes a setting in the production admin interface bypasses the repository, the test run and the review step. The next deployment may then overwrite that change, or the production value may differ from what the team believes is running. Require that production settings change only through a reviewed commit or an approved preset, and use the config changes report to find any change that skipped that path. Check who holds site administrator rights in production.

Presets carrying sensitive values

Admin presets export site settings to a file that can be imported elsewhere. If an export includes authentication endpoints, API keys or other values tied to one environment, the file becomes a copy of sensitive data that may be shared with contractors or stored in a ticket. Review each exported preset before it is committed or shared, remove environment-specific and secret values, and store the preset file under the same access rules as the repository.

Forced settings that lock administrators out

Settings forced in config.php cannot be changed in the admin interface, so an incorrect forced value can block the change needed to fix it. A typo in an authentication or email setting can stop administrators from signing in or from receiving reset messages. Test every forced setting in the staging environment first, keep a documented way to remove a forced value from the server, and make sure at least one administrator account can sign in through a path that does not depend on the setting under change.

File permissions on config.php

config.php holds the database credentials and the path to the data directory. If the file is readable by other local users or served by the web server, those credentials are exposed to anyone who can reach the host or request the file. Set the owner and group so that only the deployment user and the PHP runtime can read it, deny web access to it, and confirm the permissions after every deployment that rewrites the file. Ask the hosting team to verify these permissions on each environment.

Who can read the config changes report

The config changes report records which administrator changed which setting and the old and new values. That record is useful for audits, but it can also reveal internal hostnames, directory structures and security settings to anyone with access to the report. Limit the report capability to a small set of reviewers through the roles system, confirm which roles can view it in each environment, and treat its exports as sensitive records.

Keeping secrets and site-specific values out of version control

Some Moodle settings are shared across every environment, but others are true to one site only and should never be committed. The site URL ($CFG->wwwroot), the database host, name and credentials, the mail server and sending account, the data directory path ($CFG->dataroot) and the SMTP and LDAP bind passwords all change between test and production. So do the keys for external services that Moodle calls, such as video, storage or AI providers. If these values sit in a shared repository, every clone carries live credentials, a test copy can send email to real learners, and a restore from one environment can quietly point at another environment's database. Teams should write down this list for their own site before they write any configuration, because the list defines what the repository is allowed to contain.

The usual split is one shared settings file that holds forced settings, presets and plugin defaults, plus a small environment file that holds only the values above. In practice, config.php reads its environment values from variables or a file that the deploy process writes in place, so the repository only contains the reading code. Credentials are fetched at deploy time from a secrets store the organization controls, such as a self-hosted vault, and written to the server with restricted file permissions owned by the web server's PHP user or by root. Confirm that your secrets store and deployment tooling keep these values out of build logs, container images and shell history, and that rotating a database or mail password is a change you can make without editing the repository.

Plan two checks before the first promotion. First, scan the repository and the exported admin presets for anything that looks like a password, token or hostname from a live environment, and add that scan to the pipeline so it fails the build. Second, confirm that the config changes report and the environment values line up after a restore or a copy of production into test, because copying the database without rewriting the environment values is a common cause of test sites contacting live services. Ask your Moodle hosting team to confirm which of these settings the installed version lets you set from the environment, since the supported approach depends on your own deployment method.

What to confirm before relying on configuration as code

Configuration as code only holds if the target Moodle release accepts the same settings, runs on the same stack and starts from a supported version. The items below are the checks to finish in the target environment before you build presets, forced settings or a promotion process around them.

Supported PHP and database versions

Confirm the PHP and database versions your environment runs against the target release before you export anything. Moodle 5.1 requires 64-bit PHP 8.2 or later, with PHP 8.3 and 8.4 supported, and accepts PostgreSQL 15, MySQL 8.4, MariaDB 10.11 or SQL Server 2017 or later. Moodle 5.3 requires 64-bit PHP 8.3 or later and PostgreSQL 17. A preset built on one stack may behave differently on another, so test the import on the same versions you run in production.

Moodle 5.3 notes

Upgrade starting point

Check that your current site can reach the target release in one step. Moodle 5.1 requires sites to be on Moodle 4.2.3 or later, and Moodle 5.3 requires Moodle 4.4 or later. If you are on an older branch, the settings you exported may not match the schema or defaults of the new release, so plan an intermediate upgrade before you rely on the exported configuration.

Document root change in 5.1

From Moodle 5.1, the web server document root must point to the new public directory instead of the main Moodle folder. Your deployment templates, reverse proxy rules and environment definitions must reflect this path in test and production alike. Otherwise the site may show directory listings or errors, and a config promotion can appear to fail when the real fault is the web server path.

Reach of presets and config.php

Confirm which settings a preset or a forced config.php entry can reach in the target version. Forced settings lock values at the code level, but not every admin setting is exposed the same way, and some values live in the database rather than in files. Test a sample of your critical settings on a staging copy and record which ones the export captures and which you must set by hand.

Plugin settings coverage

Confirm whether the plugin settings you depend on, such as authentication, enrolment, block and local plugin configuration, are included in your presets and in the config changes report. Core settings and plugin settings are not handled the same way. Check each third-party plugin on staging, because a plugin that stores values outside the standard settings table will not travel with the export.

Config changes report coverage

Confirm that the config changes report (report_configlog) in your target release records the changes you need for audit and rollback. Test a change in staging, check that the entry shows the setting, old and new values and the user who made it, and confirm your change process reads from that record. This is the evidence trail that connects a promoted change back to an approved request.

Moodle report source

Using the config changes report as change evidence

Moodle core includes a config changes report (report_configlog) that records changes made to site configuration through the administration interface, so teams can see who changed a setting, when, and what the value was before and after. Use it as the applied-state side of a comparison. Export the intended settings from your version-controlled config.php and presets, then compare them against the values the report and the live site show for the same environment. Any difference is either an undocumented change that needs a decision or a setting that was never promoted from test. Run the comparison after every change window and keep the output with the change record. Confirm in your own test site exactly which settings the report captures, because it is not a complete list of every value Moodle stores, and some settings set through config.php will not appear as edits in the interface.

The report helps with change records because it ties an individual configuration edit to a user account and a timestamp, which a change ticket can reference. A typical record for a configuration change would hold the ticket number, the reviewer who approved it, the environment where it was tested, the promoted commit or preset version, and the config changes report entries from the production window. Include a short note for changes made outside the interface, such as edits to config.php deployed by your pipeline, since the report will not attribute those to the person who merged them. Ask your team to confirm how deployment logs, Git history and the report line up for each environment.

The report does not prove on its own that a control operated as designed. It shows that a recorded edit occurred, not that it was approved, correct, tested or the only change made. Administrator accounts can be shared or misused, and the report depends on the integrity of the database and the logging that surrounds it. Whether this evidence meets a particular regulatory requirement is a determination for the independent auditor or assessor who reviews your environment, not for the platform or for DeployOpen. Agree with your auditor early which records they expect, how long they must be retained, and how they will sample them.

Moodle settings as code cost, effort and what it needs from your team

What drives the cost of managing Moodle settings as code?

The cost follows the number of environments, the number of plugins that carry their own settings, how many people own settings, and how much version control practice already exists. Each extra environment adds a promotion path to test and document. Each plugin adds settings to map, export and review. Many settings owners mean more approval steps and more drift to resolve. A team that already keeps Git-based change records and runs deployments from them starts from a much shorter path than one that edits settings by hand in the admin screens. Ask any quote to list which of these factors it assumes and what it leaves to your team.

How long does a first settings-as-code workflow take to set up?

No duration is fixed here, because it depends on the environments in scope, the plugins involved and how many settings need an owner. The first workflow usually takes the most time: agreeing what goes into config.php, what is exported with admin presets, and how the config changes report is reviewed before a change is promoted. Later changes are faster once the pattern is set. Ask for a written scope that lists the environments, the settings groups covered and the acceptance test used to show that a change reached production unchanged.

What does the work need from our team?

The work needs named people from four groups: a Moodle administrator who knows the current settings, a service owner who approves changes, someone who runs the Moodle servers and deployment tooling, and a reviewer who checks the change record. You will also need access to a test environment that matches production closely enough to prove a change, and a place to store configuration in version control. Expect to make decisions about which settings are locked in config.php and which stay editable by administrators.

Can an internal team manage Moodle settings as code without a partner?

Yes, an internal team can do it, provided it has someone who can read Moodle's configuration files, operate version control and understand the admin presets and config changes report. The usual gap is not tooling but time and ownership: the same people often run upgrades, incidents and course requests. A partner is most useful for the initial design, the mapping of settings to owners and the first promotion cycles. Confirm with your own team which skills are present before you decide the split.

How do settings survive a Moodle upgrade?

Settings stored in the database persist through an upgrade, but new releases can add, rename or remove settings and change defaults. Settings forced in config.php keep their values, but a removed setting may stop having any effect. Before each upgrade, review the release notes for the version you are moving to, rerun the exported presets against the new version in test, and check the config changes report for unexpected differences. The release notes for Moodle 5.1 and Moodle 5.3 list version-specific changes that you should check against your configuration.

Does managing settings as code replace backups?

No. Settings as code records what the configuration should be and who changed it. It does not hold user data, course content, the moodledata directory or a consistent copy of the database. You still need a whole-site backup that captures the database, moodledata and code together, plus tested restores. Keep the configuration repository as a separate record and confirm where each copy lives and how long it is kept with your own recovery plan.

What should we ask for in a quote for this work?

Ask for a written scope that names each environment, the settings groups covered, the plugins whose settings are mapped and the tools used to export and promote changes. Ask which deliverables you receive, such as the configuration repository, a promotion runbook, review checklists and handover notes. Ask what is one-time setup and what recurs, including upgrade reviews and ongoing support, and which items the quote assumes your team provides. Ask how acceptance is tested and how changes found in production but not in version control are handled.

How DeployOpen works on this

DeployOpen plans, implements and supports self-hosted Moodle inside your own infrastructure, including the way its settings are versioned and promoted between environments. Each engagement starts with a written scope, so the settings to be locked, exported and promoted are agreed before any change is made to your sites.

How we scope

  • Inventory which settings must be forced in config.php and which can stay editable in the admin interface.
  • Agree which admin presets, plugin settings and role configurations will be exported and imported between environments.
  • Define how the config changes report will be reviewed, who approves changes and where review records are kept.
  • Record the test and production environments, their Moodle versions and the promotion steps in the written scope.

How we build

  • Build a version-controlled configuration baseline with forced settings, presets and exported plugin settings for your Moodle version.
  • Test each promotion on a staging copy, checking that the config changes report matches what was intended.
  • Verify that production-only values such as secrets, URLs and file paths stay out of shared configuration files.
  • Document each change path so administrators can repeat a promotion without relying on one person's memory.

How we hand over

  • Deliver the configuration repository, promotion runbook and rollback steps agreed in the written scope.
  • Walk your administrators through the presets, forced settings and config changes report during a handover session.
  • Provide a record of the test results for each promotion so your compliance or audit teams can review the trail.
  • Confirm with you which items remain your responsibility, such as access to the repository and approval of production changes.

How we support

  • Offer ongoing support for configuration changes, Moodle upgrades and periodic reviews of drift between environments as a retainer.
  • Re-run configuration checks after each Moodle minor or major release, since settings may change between versions.
  • Adjust the promotion process as your teams, environments or identity and integration setups change over time.

Sources and further reading

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.