Moodle maintenance mode and CLI admin scripts: when a change window needs them
When a live learning platform needs a planned change window, the administrator has to decide who can use the site while changes run. Maintenance mode and the command line admin scripts give that control: maintenance mode blocks user access while the site is changed, and the CLI scripts run the operational tasks (upgrades, cache purges, session clearing, plugin removal and course deletion) without relying on the web interface. Both are needed because a site that is half upgraded or has stale caches can fail in ways users see immediately, and because some tasks are faster and safer from a shell than from a browser.
The main tools live under the admin/cli directory of the Moodle codebase. Typical scripts cover maintenance mode (admin/cli/maintenance.php), upgrades (admin/cli/upgrade.php), cache purges (admin/cli/purge_caches.php), session handling (admin/cli/kill_all_sessions.php), plugin uninstalling (admin/cli/uninstall_plugins.php) and course deletion. The exact set, options and flags change between Moodle versions, so confirm each script name and its help output (for example, by running it with --help) in the codebase you have installed before you write a runbook around it. Your change plan should also state which script runs under which PHP user, because file ownership mistakes are a common cause of failed CLI runs.
Before the window opens, confirm that CLI uninstalling is the only route you intend to use. The config.php setting that restricts plugin uninstalling to the CLI script is documented in the sample configuration file, and it affects every administrator on the site. Ask your Moodle partner or internal team to record which scripts are approved for production, who may run them, and how each run is logged. Destructive commands such as course deletion need a second check of the target identifier, since the command accepts a shortname and, from Moodle 5.2, an ID number as well. Confirm both behaviors in the release notes for your version before you rely on them.
Which CLI script or setting fits which change
This table compares the Moodle CLI tools and settings administrators use during change windows, showing the job each one does, when it fits and the main risk. Read each row as a decision: match the change you are making to the tool, then check the risk column before scheduling. Exact option names vary by release, so confirm them in the installed version before a change window.
| Tool or setting | What it does | When it fits | Main risk |
|---|---|---|---|
| Maintenance mode | Puts the site into a state where normal users cannot sign in while admins keep access, so changes run without active traffic. | Before upgrades, database or file changes, and plugin installs that touch live data. | Users are locked out for the full window. Forgetting to turn it off after the work leaves the site appearing down. |
| Upgrade script (admin/cli/upgrade.php) | Runs the database and code upgrade steps for a new Moodle or plugin version from the command line. | Applying a new core or plugin version after code is in place, with a verified backup. | Interrupted or failed upgrades can leave the database partly migrated. Confirm the minimum starting version and server requirements for the target release first. |
| Cache purge (admin/cli/purge_caches.php) | Clears Moodle's application caches so changed settings, themes and language strings take effect. | After config, theme or language changes, or when pages show stale content. | Purging on a busy site can cause a short spike in load as caches rebuild. Schedule it outside peak use where possible. |
| kill_all_sessions.php | Ends user sessions from the command line, which is useful when access must be revoked quickly or before maintenance. | Before a window that changes accounts or auth settings, or after a suspected account compromise. | Users lose unsaved work in open pages. Moodle 5.2 made this script more flexible, so confirm the exact options in your release. |
| uninstall_plugins.php | Removes an installed plugin and its data through the CLI, and can be restricted to this route with a setting in config.php. | When standardising a fleet or enforcing change control so plugins are removed only in planned windows. | Plugin removal can delete plugin tables and data permanently. Confirm the setting name in config-dist.php and take a backup first. |
| Course deletion by shortname | Deletes a course from the command line. Moodle 5.2 allows the course to be identified by shortname or ID number as well as by ID. | Bulk clean-up of test or duplicate courses, or removing courses that were created by a migration run. | Deletion is hard to reverse, and shortnames may not be unique across categories. Confirm the option names in your release and test on a copy first. |
| Confirm before any window | Checks the release notes, option names and backup status for the tool you plan to use. | At planning time, for every change in the window. | Relying on remembered syntax from an older release. Check the release notes for the version you run. |
Restricting plugin uninstalls to the CLI
Moodle lets you limit plugin removal to a command line script, so uninstalls happen during planned windows with a record of who ran them. The cards below cover what the setting does, what it costs administrators in extra steps, and what to check before you turn it on.
What the setting restricts
The config-dist.php file can restrict plugin uninstalling to the CLI script admin/cli/uninstall_plugins.php. Once it is enabled, removing a plugin from the web interface is no longer the normal route, so an uninstall becomes a deliberate act run from a shell. Confirm the exact configuration key and its behavior against the config file in your Moodle version before you rely on it, because the wording of the setting is defined there rather than in this page.
Moodle config-dist.phpWhy removals move to a window
Uninstalling a plugin can remove its tables, settings and any content that depends on it, so a removal during term time can disrupt learners. Requiring the CLI script pushes these changes into the same change window you use for upgrades and database work. Plan the window with the teams who own affected courses, and record which plugins are scheduled for removal.
Audit clarity through shell access
A CLI run is tied to a named operator with shell access on the server, and the command and its output can be captured in your change ticket or terminal logging. Web uninstalls depend on the administrator's browser session, which is harder to attribute in a review. Check that your shell logging, sudo policy and ticket process actually record these runs, because Moodle's own logs may not capture the shell context.
Extra steps for administrators
Administrators must log in to the server, change to the Moodle directory and run the script as the correct PHP user, then confirm the result. This adds time and a dependency on people with server access, which can slow urgent clean-up. Decide in advance who may run the script, who approves it, and how an emergency removal is handled.
Confirm before enabling
Before you enable the restriction, confirm the file path and key names in your config, check that the script exists at admin/cli/uninstall_plugins.php in your version, and test on a staging copy with the same plugins. Confirm that the PHP user, file ownership and config.php permissions allow the script to run. Also confirm that your backup and rollback steps are in place before the first real removal.
Setting up a repeatable change window in Moodle
This sequence turns a Moodle upgrade, plugin change or cache purge into a predictable window with a known rollback point, a quiet site and a clear record that the site is healthy before users return.
Confirm the target release and its requirements
The platform owner and the Moodle administrator agree the target version, then check it against the server requirements for that release: the PHP version, the database engine and version, and the minimum version the site must already be running to upgrade. Confirm the web server document root will point to the correct folder if the target release changes it. Check the release notes for the installed and target versions, and check any plugins against their supported Moodle versions. The step is done when the requirements are written down and every item is either met or has a named owner to fix it before the window opens.
Take and verify a full backup
Back up the database, the moodledata directory and the code together, so the three can be restored to the same point in time. Course backups do not cover this, and a backup taken from only one of the three may not restore cleanly. Store the copies outside the server being changed, then run a test restore on a separate environment to prove the backup is usable. The step is done when the restore test completes and the team records the backup time, location and the person who signed off on it.
Enable maintenance mode
Turn on Moodle's maintenance mode from the administration tools or the CLI maintenance script so that ordinary users are stopped from signing in and working while changes are made. Confirm the site shows the maintenance message to ordinary users, and that administrator access still works for the people running the window. Exact commands and options depend on the installed version, so take them from that version's documentation. The step is done when a test account is blocked and an administrator account can still reach the site.
Stop cron and ad hoc task runners
Pause the scheduler that runs Moodle's cron, including any system cron entries or additional runners on larger sites, so that no new scheduled or ad hoc tasks start during the change. Let any task already running finish, and check the ad hoc task queue for tasks that are stuck or still running before proceeding. Re-enable the scheduler only after the window closes. The step is done when no Moodle cron or task processes are running on any application server and the team has noted the queue state.
Kill active sessions
Terminate existing user sessions so that no one is still signed in with the old code or database state. Use the session-killing CLI script available in the installed version, and confirm its options in that version's documentation, since behavior changed in recent releases. Check that the session store is cleared, and that a logged-in test account is signed out. The step is done when the session count is zero or only administrator sessions remain, and that count is recorded.
Run the upgrade or purge command
Run the upgrade script, plugin change or cache purge command that the window was planned for, from the Moodle directory and as the PHP user that owns the code. Capture the output to a log file so that any errors or warnings can be reviewed later. If a plugin must be removed, check whether the installed version restricts uninstalling to the CLI script. The step is done when the command exits without errors and the log shows that every step completed.
Check status reports and environment
Open the site's status and environment check reports as an administrator and review any errors or warnings, including database, plugin and file permission checks. Test a sample of key pages, such as login, a course page, and a quiz or assignment page, with an ordinary test account. Resolve issues before opening the site to users. The step is done when the status report has no unresolved errors and the test account can complete the basic tasks.
Disable maintenance mode and resume tasks
Turn off maintenance mode, restart cron and task runners, and confirm the ad hoc task queue begins draining normally. Watch the logs and the queue for the first period after reopening, then record the window's outcome, including the start and end times, the versions changed, the backup reference and any issues. Keep the restore plan available until the team agrees the change is stable. The step is done when users can sign in, tasks run, and the change record is filed with the team's sign-off.
Security and operational risks of CLI access
Command line tools can change a live Moodle site faster than the web interface can, and some of their actions cannot be undone. The cards below cover who should hold server access, which commands need extra care, how to record change windows, and what users experience when sessions are ended mid-task.
Limit who holds server shell access
Maintenance mode, upgrades, cache purges and plugin removal all run as shell commands under the web server or PHP user. Anyone with that access can change the site without leaving a trace in Moodle's own logs. Restrict shell accounts to named administrators, use individual keys instead of shared logins, and confirm which user owns the Moodle code and moodledata directories.
Treat course deletion as irreversible
The CLI course deletion script removes a course by identifier, so a mistyped shortname can remove the wrong course. Moodle 5.2 allows deletion by shortname or ID number, which makes matching more flexible and raises the chance of a wrong match. Before running it, list the matching courses, confirm the identifier with the requester, and take a course backup first.
Moodle 5.2 notesRestrict plugin uninstall to the CLI
The config-dist.php file can restrict plugin uninstalling to the CLI script admin/cli/uninstall_plugins.php. Once that restriction is set, removing a plugin through the web interface is blocked, so the change is deliberate and goes through the shell. Confirm the setting in config.php on every environment, and check that it is not overridden in one place only.
config-dist.phpLog every command in change windows
Moodle's own logs do not capture everything an operator types on the server. Record the start and end time, the operator, each command run, its output and the reason in a change log kept outside the server. Shell history alone is easy to clear or lose, so copy the terminal session or use a session recorder where policy allows it.
Plan the effect of killing sessions
The kill_all_sessions.php script ends every active login, including users who are midway through a quiz attempt, an assignment submission or a form. Unsaved answers can be lost, and some activities may not resume cleanly. Announce the window in advance, schedule it when few users are active, and agree with course owners how in-progress work will be handled.
Keep a record for audit review
Auditors and internal reviewers often ask who changed the platform, when, and why. Keep one record per change window that links the request, approval, commands run, backup reference and verification results. Store it where administrators cannot edit it after the fact, and review the record against the security report in Moodle after each window.
Questions teams ask before running Moodle change windows
Can our own administrators run Moodle maintenance mode and CLI scripts without a partner?
Yes, if the team has someone comfortable with a Linux shell, the web server and the PHP user, and a tested rollback. The core scripts for maintenance mode, upgrades, cache purges, session handling and plugin uninstalling are part of Moodle's command line tooling, so a competent internal administrator can run them. The risk sits in the surrounding work: confirming the backup is restorable, knowing which plugins block an upgrade, and making sure the right person can make a go or no-go call during the window. Teams that run only one change a year often find that the skill fades between changes, so the question is less whether they can run the commands and more whether they will run them correctly under time pressure.
What drives the effort of a Moodle change window?
The effort follows the change, not the command. The main drivers are the size of the jump between versions, the number and age of third-party plugins, custom themes and local code, the database engine and its size, and how many environments the change must pass through before production. Each of these adds testing, rollback preparation and communication work. A minor point release on a site with few plugins is a short exercise. A major upgrade that crosses a server requirement change, such as a new PHP or database minimum, usually adds server preparation and a longer test cycle. Ask any provider to break its quote into preparation, test runs, the window itself and post-change checks.
What skills and staff time does a change window need from our team?
At minimum, a team needs one person who runs the change, one who can approve or stop it, and someone who owns the database and file restore. The runner needs shell access, familiarity with Moodle's CLI scripts and the ability to read the upgrade output. The approver needs the authority to extend or abort the window. Plugin owners or the teams who depend on custom features should confirm behavior in a test copy before the window opens. Staff time is both one-time and recurring: one-time for documenting the runbook and building a staging copy, and recurring for every release cycle. Ask whether your team has these roles covered by named people, not by assumption.
How long does a Moodle change window take?
No supplied figure sets a general duration, so the honest answer depends on site size, plugin count, database size and how much preparation was done in advance. The window itself covers enabling maintenance mode, taking a verified backup, running the upgrade or script, purging caches and checking the site before users return. Much of the elapsed time often comes from the upgrade script on a large database and from plugin updates that need attention. Teams should measure the duration on a staging copy of production, not estimate it from a small test site, and agree a hard cut-off time for rollback. Ask for the measured staging timings and the planned rollback point in any written plan.
Which Moodle version and server requirements should we check before a change window?
Check the minimum starting version and the server stack for the target release before scheduling anything. For example, Moodle 5.1 requires 64-bit PHP 8.2 or later and sites must be on Moodle 4.2.3 or later to upgrade, while Moodle 5.3 requires 64-bit PHP 8.3 or later and sites must run Moodle 4.4 or later. From Moodle 5.1, the web server document root must point to the new public directory, so the web server configuration needs a change in the same window. Confirm the supported database versions against the release notes for your target, and plan any server upgrade as a separate, earlier step.
Is it safe to use CLI commands to uninstall plugins or delete courses?
It can be safe with controls, and irreversible actions deserve the most caution. Moodle's config-dist.php can restrict plugin uninstalling to the CLI script admin/cli/uninstall_plugins.php, which keeps the action out of the web interface and in a logged, deliberate step. Since Moodle 5.2, CLI course deletion can use a shortname or ID number, which makes it easier to target the wrong course if the identifier is ambiguous. Require a verified backup, a dry run on staging, a second person reviewing the identifier and a written record of the command and its output. Confirm the exact options in the release notes for your version before you rely on them.
When is outside help worth paying for a Moodle change window?
Outside help is worth considering when the internal team lacks a tested rollback, when the site carries many custom plugins or themes whose compatibility is unknown, when the change crosses a major version with new server requirements, or when the site supports regulated or high-stakes learning and cannot absorb a failed window. DeployOpen plans, implements, upgrades, documents and supports self-hosted open-source platforms inside your own infrastructure, so a quote can cover a single window, staging preparation, a runbook or a recurring support retainer. Ask for a written scope with deliverables and timelines before work starts, and ask what is one-time and what recurs.
Does a successful change window prove the site is compliant?
No. A successful window shows the platform is running the intended version and configuration at that point, which is useful evidence, but it does not establish compliance on its own. Compliance readiness depends on the controls, records and evidence your regulator or accreditor expects, and DeployOpen prepares systems, controls and evidence for compliance assessments without issuing audit reports or certifications. Independent auditors and certification bodies perform those assessments. Keep change records, approvals, backup verification and post-change check results as part of the evidence trail.
How a change window moves through maintenance mode and the CLI
A change window starts with a verified backup before anything else changes. Administrators then enable maintenance mode, let background work drain, and kill remaining sessions so no user writes data mid-change. CLI scripts run the planned changes, and the status checks decide the outcome: if any check fails, the team goes to restore from the backup rather than pushing forward. Only after the checks pass does maintenance mode come off.
The sequence of steps in a Moodle change window, including the restore branch for failed checks.
How DeployOpen plans and runs Moodle change windows
DeployOpen plans Moodle change windows as written, fixed-scope work inside your own infrastructure. We set out which maintenance mode, upgrade, cache, session and CLI steps your team needs, then build and rehearse the runbook so the live window follows a tested sequence.
How we scope
- Inventory every change your window touches: upgrades, plugin installs, cache purges, session clears and course deletions
- Confirm the Moodle version, PHP and database versions, and the web server document root before any step is planned
- Agree in writing which CLI scripts run, who runs them, and which steps need a second approver
- Define rollback points and the criteria for stopping a window, documented before work starts
How we build
- Write a step-by-step runbook using the CLI scripts for your exact Moodle release and server layout
- Rehearse the full window on a copy of production so timings and errors are observed before go-live
- Set guardrails such as restricting plugin uninstalls to the CLI where your configuration allows it
- Test course deletion by shortname or ID number on non-production data to confirm the selector your team will use
How we hand over
- Deliver the runbook, rehearsal notes and a checklist that operators can follow during a live window
- Document maintenance mode enable and disable commands, expected output, and how to confirm the site is serving users
- Record which settings, scripts and accounts were used so the change is traceable afterward
- Walk your operations team through the runbook and the rollback steps before the first real window
How we support
- Support for future windows can be added through a retainer covering upgrades and updated runbooks
- Retainers can include review of each new Moodle release's CLI or configuration changes before your next window
- Ask for a retest of the runbook after any change to PHP, the database or the Moodle code base
- Confirm response expectations, scope of out-of-hours support and handling of emergency rollbacks in the written agreement

