Running Moodle on Windows Server with SQL Server in a Microsoft shop
Moodle runs on Windows Server with Microsoft SQL Server, and the current minimums are Microsoft SQL Server 2017 or later for Moodle 5.1 and SQL Server 2019 or later for Moodle 5.3. A Microsoft-standard organization can therefore reuse its existing estate, but the Windows path carries more moving parts than a Linux build, so the decision should rest on the release you will run for the next several years. The web tier is either IIS or Apache on Windows with PHP 64-bit, PHP 8.2 or later for Moodle 5.1 and PHP 8.3 or later for Moodle 5.3. The database, the web server and the moodledata directory must all be sized and secured together.
Confirm three things before you commit. First, check the PHP extensions and the FastCGI or FastCGI-equivalent handler your IIS or Apache build uses against the Moodle install documentation for your target release. Second, plan file locking explicitly. The config.php settings for lock factories are described in the sample configuration file, which notes that SQL Server needs particular attention and lists file, database record, MySQL and PostgreSQL advisory lock options. Test the lock factory you choose under concurrent load on a staging copy, because the default choice is not always the one a Windows-hosted site should keep. Third, from Moodle 5.1 the web server document root must point to the new public directory, not the main Moodle folder, or visitors may see directory listings or errors. Write that rule into your IIS site definition or Apache virtual host from the start.
Sites moving to Moodle 5.3 or later from older releases should also check the upgrade path against the Moodle 5.3 release notes, which state that sites must run Moodle 4.4 or later to upgrade. Plan for the ongoing cost of this stack: Windows Server and SQL Server licensing, patching windows, and staff who can tune PHP and IIS are recurring items, while the Moodle code itself is GPL-3.0 licensed. If your team runs Linux and PostgreSQL well, moving to that stack later usually means repeating the database migration and rebuilding the web tier, so price that step into the decision now.
Which Windows web server and database choices fit
This table compares IIS and Apache on Windows with SQL Server, and PostgreSQL or MariaDB on Linux as the alternative. Read each row for the fit, the document root and PHP setup, and the locking and upgrade effects. The main takeaway is that the Windows path works for a Microsoft shop, but the minimum SQL Server version rises with each Moodle release, and the Linux path gives more version headroom.
| Option | When it fits | Document root and PHP | Locking and upgrades |
|---|---|---|---|
| IIS with SQL Server | Microsoft shop with Windows Server and SQL Server administration already in place | From Moodle 5.1, point the IIS site at the /public directory. Confirm the PHP handler and 64-bit build for your target release. | Review the SQL Server locking notes in config-dist.php and set the lock factory in config.php. Moodle 5.3 requires SQL Server 2019 or later. |
| Apache on Windows with SQL Server | Team already runs Apache and wants the same server model on Windows | From Moodle 5.1, set the DocumentRoot to /public. Confirm how your Apache build loads PHP and that it meets the 5.3 PHP 8.3 minimum. | Same SQL Server locking review as IIS. Confirm the SQL Server version floor for each planned upgrade before choosing the build. |
| PostgreSQL on Linux | Team can operate Linux and wants the widest version headroom for future upgrades | Set the web server root to /public on Nginx or Apache. Moodle 5.3 requires PHP 8.3 or later, with 8.4 supported. | PostgreSQL advisory locks are one of the lock factories listed in config-dist.php. Moodle 5.1 requires PostgreSQL 15 and 5.3 requires PostgreSQL 17. |
| MariaDB on Linux | Team already runs MariaDB and wants a MySQL-compatible option on Linux | Set the web server root to /public from Moodle 5.1. Confirm PHP extensions and the 64-bit build for the target release. | Moodle 5.1 requires MariaDB 10.11 and 5.3 requires MariaDB 11.4. Confirm which lock factory suits MariaDB before go-live. |
| SQL Server 2017 or 2019 | Existing SQL Server estate that must stay in place for policy reasons | Document root and PHP work are the same as the chosen web server. Plan the PHP version alongside the database version. | Moodle 5.1 accepts SQL Server 2017 or later. Moodle 5.3 requires SQL Server 2019 or later, so a 2017 instance will need upgrading before that release. |
| Moving to Linux later | Windows build is in place but the team expects to change platforms within a few upgrade cycles | The /public document root and PHP setup carry over to Linux, but the web server configuration is rebuilt. | Plan the database migration as a separate project with its own testing. Confirm the lock factory and backup method for the new database before cutover. |
How to set up Moodle on Windows with SQL Server
This sequence takes a Windows Server host from a version check to a running Moodle site with a locked-down database login, a correctly placed web root and data directory, scheduled cron, and a clean post-install check. Each step ends with a check you can record before moving on.
Confirm the target release and minimums
The platform owner and the lead administrator choose the Moodle release before anything is installed, then check its PHP, SQL Server and upgrade-path requirements in the release notes for that version. Moodle 5.1 requires 64-bit PHP 8.2 or later and Microsoft SQL Server 2017 or later, while Moodle 5.3 requires 64-bit PHP 8.3 or later and SQL Server 2019 or later, so the chosen release decides which PHP and SQL Server builds are acceptable. Record the release, PHP version and SQL Server version in the build log. The step is done when those three values are written down and confirmed against the release notes, and the release is one your organization intends to keep supported.
Install 64-bit PHP and required extensions
The server administrator installs the 64-bit PHP build that matches the chosen release, using the Windows packaging your team already supports. Enable the PHP extensions that Moodle requires for SQL Server, including the Microsoft SQL Server drivers for PHP, and confirm the php.ini limits that the Moodle environment check reports. Run the Moodle environment check after the Moodle code is unpacked, not before, so the results reflect the real site. The step is done when PHP reports the correct bitness and version from the command line and the environment check shows no required items failing.
Create the database and a dedicated login
The database administrator creates an empty database for Moodle on the SQL Server instance, with a collation and settings that the release notes allow, and creates a separate SQL login that owns only that database. Do not reuse a system administrator account or a shared service account for Moodle. Confirm that the login can connect, create and alter tables and indexes in its own database, and has no rights on other databases. The step is done when a test connection from the web server host succeeds with that login and the database is empty and ready for the installer.
Point the web server at the public directory
The web administrator configures IIS or Apache so that the document root is the /public directory inside the Moodle code folder, not the main Moodle folder. From Moodle 5.1, pointing the root at the main folder can expose directory listings or cause errors, so this setting must be correct before the site is reached in a browser. Set the PHP handler for the site, confirm that static files are served, and check that requests to the code folder outside /public are not reachable. The step is done when the site home page loads through the web server and a request for a file outside /public returns a refusal.
Place moodledata outside the web root
The server administrator creates the moodledata directory on a path that is not under the web root and grants read and write access only to the account running PHP. Keep it on local storage or a share that the team has tested for file locking and reliability, since the data directory holds uploads, caches and session-related files. Confirm that a browser request to the data directory path is not served. The step is done when the directory exists, the PHP account can write to it, and the installer accepts the path without warnings.
Configure locking in config.php
The administrator edits config.php to set the database connection details and the lock factory that suits a SQL Server deployment. Moodle's shipped configuration notes describe file, database record, MySQL and PostgreSQL advisory lock factories, and the SQL Server choice must be made deliberately using the options the release supports, so review the config-dist.php notes for the chosen version before setting the value. Store the file outside the public tree where the environment allows it, and restrict file permissions so only the service account can read it. The step is done when config.php loads, the site starts without lock errors under a short test with several concurrent page requests, and the chosen lock setting is recorded in the build log.
Schedule cron as a Windows task
The Windows administrator creates a scheduled task that runs the Moodle cron script at a fixed interval using the same PHP build and the same service account as the web server. Scheduled tasks, email sending, course backups and many plugins depend on cron, so a missing or failing task is one of the most common causes of quiet breakage. Set the task to run whether or not the user is logged on and to log its output to a file. The step is done when the task runs manually without error, the log shows a completed cron run, and the Moodle scheduled task list shows recent run times.
Run the post-install checks
The Moodle administrator completes the web installer, then opens the site administration pages for the environment check, the security overview and the system errors report, and resolves every item the checks flag as required. Confirm that the site can send a test email, that the cron status is current, and that the administrator account uses a strong credential and an approved sign-in method. Save the results of these checks with the build record so the next upgrade or audit has a starting point. The step is done when the checks show no required failures, the test email arrives, and the build record is signed off by the platform owner.
How locking changes the SQL Server build
Locking is the decision in a Moodle on SQL Server build that most often gets left at its default and then matters later. Moodle uses locks to stop two processes from changing the same thing at once, such as cron tasks, scheduled jobs and session-sensitive operations. The lock factory determines where that coordination happens. Moodle's config.php settings, documented in the config-dist.php file in the Moodle repository, offer several lock factories, including file-based locking, database record locking, and advisory locks on MySQL and PostgreSQL. The file-based and database record options are the ones a Microsoft shop will weigh first, because they do not depend on a database engine feature that is specific to the other platforms. Your team should read the lock factory notes for the exact Moodle release it plans to run, since the available options and defaults are release-dependent and the notes are the authority for your version.
The choice depends first on topology. On a single web server with one cron host, the default locking is usually sufficient for coordination, and the main risk is misconfiguration rather than contention. Once you run multiple IIS or Apache nodes behind a load balancer, or split web and cron roles across machines, every node must agree on the same lock behaviour. A file-based lock only works across machines if all nodes can reach the same lock location, so a file share on Windows becomes a shared dependency that needs its own availability and permission planning. A database-based lock keeps coordination inside SQL Server, which removes the file share but adds load and locking behaviour to the database you are already tuning.
Test the choice before go-live rather than assuming it works. Run cron on two nodes at the same time in a staging environment, trigger a scheduled task that writes to the same records, and confirm that only one instance proceeds while the other waits or exits cleanly. Record which lock factory is active, who owns the setting in your configuration management, and what happens when the shared lock location or database is unavailable. Confirm the behaviour with the Moodle documentation for your release and with your own load tests, because a lock that works on one server can still produce stalled tasks under real concurrency.
Security and operations to plan on Windows
Moodle on Windows Server with SQL Server has several moving parts: the web server, PHP, the database, the data directory and scheduled tasks. Each one needs its own account, its own patch cycle and its own backup and monitoring plan. The cards below cover the controls that most often get skipped in a first build and cause problems later.
Least-privilege SQL Server logins
Moodle needs a database login that can create, alter and drop its own tables during installs and upgrades, so the login is often granted far more rights than it needs. Create a dedicated login with ownership limited to the Moodle database, and keep it separate from administrative and reporting accounts. Confirm the minimum permissions with your DBA against the Moodle install and upgrade steps for your target release, then test an upgrade in staging before you rely on that login in production. Store the password in a protected location rather than in shared scripts.
Keeping moodledata and config.php out of the web root
The moodledata directory holds uploaded files and caches, and config.php holds database credentials and the site secret. If either is reachable through IIS or Apache, users or attackers can read files directly. Place moodledata outside the web root, restrict its NTFS permissions to the Moodle service account, and confirm that the site web root points only at the public application folder. For Moodle 5.1 and later, the document root must point to the /public directory, so verify that setting after every change to the site layout.
Moodle 5.1 notesPHP and IIS patching cadence
Windows updates, IIS, PHP and the Microsoft SQL Server drivers each ship on their own schedule, and any of them can break a Moodle site. Agree a patch window, pin the PHP version to one that Moodle supports for your release, and test each change against a staging copy with the same extensions and php.ini settings. Moodle's own release cycle also matters: check the supported PHP range and the minimum SQL Server version in the release notes before you move to a new Moodle version.
Backup and restore of database and dataroot
A Moodle backup is only useful if the database and moodledata are captured at the same point in time. Back up SQL Server with a schedule your DBA can restore from, and back up moodledata with the same cut-off, including files uploaded through the web interface. Restore both into a test environment at least once, then confirm that the site loads, files open and cron runs. Ask your storage team how snapshots of the dataroot are taken while Moodle is writing to it.
Windows service accounts for cron
Moodle depends on its cron job to send messages, process queued tasks and clean up data. On Windows, that job is usually a Scheduled Task running PHP against the Moodle cron script. Run it under a dedicated service account with the same file permissions as the web application, not under a personal administrator account. Confirm that the task keeps running after password changes, that it records its output, and that someone is alerted when it stops.
Logging and monitoring for the stack
Problems on this stack show up in several places: IIS request logs, PHP errors, Moodle's own logs, SQL Server error logs and the Windows event log. Decide where each set is collected and who reviews it, and set alerts for failed cron runs, database connection errors, disk space on the dataroot drive and certificate expiry. Keep log retention aligned with your own policy. Ask your security team which logs they need for incident response and confirm that the collection tool can read them from the Windows host.
When moving to Linux and PostgreSQL saves effort later
Moving off Windows Server and SQL Server pays off when the estate's upgrade minimums, tooling and hiring pool start working against the Moodle release cycle. The minimum database versions move forward with each Moodle release. Moodle 5.1 lists Microsoft SQL Server 2017 or later, while Moodle 5.3 lists SQL Server 2019 or later alongside PostgreSQL 17, MySQL 8.4 and MariaDB 11.4. Check the minimums for the target release against your SQL Server build and Windows Server version now, because a SQL Server or Windows upgrade forced by Moodle can land on a timetable your change calendar did not plan for. Also confirm the PHP minimum for each release, since PHP runtime upgrades on IIS or Apache carry the same risk.
Plugin and tooling availability is the second driver. Many community plugins, example configurations and server guides are written and tested on Linux with Nginx or Apache and PostgreSQL, so Windows teams often spend extra effort adapting them. Ask each plugin vendor or maintainer which database and platforms they test against before you commit, and list the plugins you need in the scope so the Windows gap is visible early. Your own operations tooling, backup scripts and monitoring agents should be checked the same way.
Hiring and cover matter as much as technology. Confirm how many staff in your team can run both the Windows stack and SQL Server locking and backup behavior, and whether a partner or managed provider covers that skill set. A database migration is a separate project from the Moodle upgrade, with its own schema conversion, data verification, cutover window and rollback plan, so scope it on its own terms. Ask any partner to quote the migration, the new platform build and the upgrade path together, and to state which Moodle release the new stack will be tested against.
Questions buyers ask about Moodle on Windows and SQL Server
Does Moodle run on SQL Server 2019 today?
Yes, with a version caveat. The Moodle 5.3 release notes list SQL Server 2019 or later among supported databases, and Moodle 5.1 accepts Microsoft SQL Server 2017 or later. Both releases also require 64-bit PHP, with 5.3 requiring PHP 8.3 or later and PHP 8.4 supported. The minimum database version changes with each release, so check the notes for the exact Moodle version you plan to install. If you are upgrading an existing site, the notes also set a minimum starting version: 5.3 requires Moodle 4.4 or later. Confirm the database minimum against your chosen release before you buy licenses or build the server, and rehearse the restore on the exact SQL Server build you will run.
What drives the effort of a Moodle build on Windows?
Effort follows the number of moving parts you must configure and keep working together. The main components are:
- Web server: IIS or Apache on Windows, with PHP connected through FastCGI or a module, and the document root set to the /public directory on Moodle 5.1 and later.
- Database: SQL Server settings, the initial schema install, backup and restore procedures, and maintenance jobs.
- File storage: the moodledata directory with correct Windows permissions, sizing for backups and media, and whether it sits on a network share.
- Locking, sessions and caching: the lock factory set in config.php and the session and cache handling sized for your concurrent users.
Effort rises with each integration, custom plugin and environment you add, including test, staging and production. Ask any partner to price each of these components separately in the written scope.
Can an internal team build Moodle on Windows without a partner?
Yes, if the team already has the skills. Engineers who administer Windows Server, IIS or Apache, PHP and SQL Server can install Moodle from the official source, and Moodle's documentation covers the install steps. The gap usually appears after the first install. Upgrades can span several Moodle releases, PHP versions move forward, restores must be tested end to end, cron needs scheduling, and security settings need regular review. Ask who will run the upgrade in two years and whether the team has time to rehearse it in staging. A partner can cover the build, documentation and handover on a fixed scope, and your team keeps ownership once the work is done.
What does a Moodle on Windows project need from our side?
Most delays come from missing access and unmade decisions rather than from the technical build. Plan to provide:
- A named technical owner for server, database and identity decisions.
- Access to the Windows servers, a SQL Server instance, DNS, certificates and an SMTP relay in the environment where Moodle will run.
- A decision on sign-in: which directory authenticates users and whether SAML 2.0 is required. The SAML2 Single sign on plugin is one option to confirm against your identity provider.
- Backup and recovery requirements, including retention periods and who approves restore tests.
- A staging environment and an agreed change window for the first production cutover.
When should we choose PostgreSQL instead of SQL Server for Moodle?
Choose PostgreSQL when no policy, contract or team skill requires SQL Server and your hosting is moving toward Linux or containers. Other common triggers include a team that already runs PostgreSQL in production and a plan to adopt Kubernetes, where Linux images simplify the stack. The Moodle 5.3 release notes list PostgreSQL 17 among supported databases, and Moodle 5.1 listed PostgreSQL 15, so confirm which version your release supports. Changing database later is a migration project with its own testing, so decide before go-live. Confirm any SQL Server licensing savings against your Microsoft agreement, since a database change alters that cost.
How do lock factories affect a Moodle install on SQL Server?
Moodle uses locks so that concurrent processes, such as cron tasks and web requests, do not conflict. The config-dist.php file documents the lock factory options, which include file locks, database record locks, and advisory locks for MySQL and PostgreSQL. Read that file for the current options and any guidance that applies to SQL Server before you set a lock factory in config.php. On a single server, the file lock factory is the usual choice to evaluate first. On multiple servers, test any shared path for lock behavior before relying on it, because a network share that handles locks poorly often shows up as stuck or duplicated tasks under load.
What usually breaks after a Moodle go-live on Windows?
Most post-launch faults come from a short list of settings. The most common are:
- A web server document root that points at the Moodle folder instead of /public on Moodle 5.1 and later, which can expose directory listings or cause errors, as described in the Moodle 5.1 release notes.
- Cron not scheduled, so background tasks and notifications stop without an obvious error.
- PHP extensions or PHP versions that differ between staging and production after an upgrade.
- Permission problems on moodledata after a restore or a service account change.
- Outgoing email failing silently because SMTP settings or DNS records were never verified.
Check each item in a go-live checklist and repeat the checks after every upgrade.
How the Windows Moodle stack fits together
The request starts in the browser and reaches the web tier, where IIS or Apache hands PHP requests to the Moodle code served from the /public directory. Moodle then reads and writes SQL Server for course and user data, and stores uploads and caches in moodledata, which must sit outside the web root. A scheduled task runs Moodle's cron separately, so background jobs keep working when no one is browsing. Check that the document root points at /public, that moodledata is not reachable over HTTP, and that the cron task and the SQL Server connection both run under accounts with only the rights they need.
Requests, data stores and the scheduled cron task inside the Windows web tier boundary.
How DeployOpen scopes and delivers Moodle on Windows
DeployOpen plans, builds, documents and supports Moodle inside your own infrastructure, including Windows Server, IIS or Apache, and SQL Server environments. Each engagement starts with a written scope that fixes what is built, tested and handed over before work begins.
How we scope
- Written scope covers the Windows Server, IIS or Apache, PHP and SQL Server versions agreed with your team.
- We confirm the Moodle release and its supported database versions before any build decisions are made.
- Scope records the file storage, email, identity and locking choices, plus who owns each one after handover.
How we build
- We build the web tier, PHP runtime, dataroot location and SQL Server connection in your own environment.
- Lock factory and cron configuration are set and tested against your chosen Moodle release and database.
- Testing covers sign-in, course access, uploads, scheduled tasks and upgrade rehearsal on a staging copy.
How we hand over
- You receive configuration records, build notes, runbooks for patching and backups, and the test results.
- Handover includes a walkthrough with your Windows, database and security administrators on their own systems.
- We document any step that needs a Linux and PostgreSQL move later, so that decision stays visible to your team.
How we support
- Engagements are fixed-scope, and ongoing support, upgrades and continuous testing are available as a retainer.
- Retainer scope should be agreed in writing, including which Moodle release lines and server components it covers.
- Ask any partner to confirm how they handle upgrade planning against the Moodle release schedule before signing.

