Installing Moodle on Ubuntu with Nginx and PHP-FPM: what the server must do
This page covers how to build a production Moodle server on Ubuntu with Nginx and PHP-FPM, and what that server must do before Moodle is installed. If your organization hosts Moodle itself, the stack has to match the release you choose, not the other way around. Moodle is open-source software licensed under GPL-3.0, maintained by Moodle HQ (Moodle Pty Ltd), and it can be self-hosted or run as managed hosting through MoodleCloud or Moodle Partners. This guide assumes self-hosting in infrastructure you control.
The most important layout change for new builds is the document root. From Moodle 5.1, the web server must point to the new /public directory inside the Moodle code, not the main Moodle folder. If the Nginx root still targets the code directory, the site can show directory listings or errors, and code files that should stay private can be served. Your Nginx server block, the location rules that pass .php requests to PHP-FPM, and the deny rules for everything outside /public all need to be written around that path. Sites upgrading from older releases must move their document root as part of the change.
Choose the release first, then the runtime. Moodle 5.1 requires 64-bit PHP 8.2 or later (8.3 and 8.4 are supported), and Moodle 5.3 requires PHP 8.3 or later with 8.4 supported. Confirm the exact PHP package version available in your Ubuntu release and the database minimums for your chosen Moodle version in the release notes before you install anything. Ask your team to record the Moodle, PHP, Nginx, and database versions in a build sheet, because those four values drive every later upgrade decision.
Which Moodle release sets your PHP and database floor
Moodle 5.3 is the next long-term support release, released on 5 October 2026 according to Moodle's release schedule. General support runs until 4 October 2027 and security support until 1 October 2029, which gives it the longest planning horizon of the options on this page. Its server floor is higher than 5.1, so the PHP and database choices move with it.
- PHP: 64-bit PHP 8.3 or later, with PHP 8.4 supported.
- Databases: PostgreSQL 17, MySQL 8.4, MariaDB 11.4 or Microsoft SQL Server 2019 or later.
- Upgrade start: existing sites must already run Moodle 4.4 or later before moving to 5.3.
- Theme impact: the Classic theme is removed from core in this release, so check whether any site still depends on it.
Confirm the exact PHP extension list and the max_input_vars guidance in the 5.3 install documentation before you select the Ubuntu release and its PHP packages.
Moodle 5.1 was released on 6 October 2025. General support ended on 5 October 2026, and security support runs until 19 April 2027, so a new build on this release has a shorter remaining window than the LTS options. It is the release where the web server document root moved to the new /public directory, which changes the Nginx configuration described later on this page.
- PHP: 64-bit PHP 8.2 or later, with PHP 8.3 and 8.4 supported.
- Databases: PostgreSQL 15, MySQL 8.4, MariaDB 10.11 or Microsoft SQL Server 2017 or later.
- Upgrade start: sites must be on Moodle 4.2.3 or later to upgrade to 5.1.
- Document root: the web server must point to /public, or the site may show directory listings or errors.
If you choose 5.1, plan the move to a later release before security support ends on 19 April 2027, and confirm the extension list in the 5.1 install documentation before you build the PHP-FPM pool.
Moodle 5.2 was released on 20 April 2026. Security support runs until 4 October 2027. The researched figures for this release cover its support dates only, so the PHP and database minimums must come from its own release notes and install documentation. Do not carry the 5.1 or 5.3 numbers across to 5.2 without checking them.
- Support window: security support until 4 October 2027, which is shorter than the 5.3 LTS window.
- PHP minimum: confirm the minimum PHP version and the supported higher versions in the 5.2 requirements.
- Database minimums: confirm the supported PostgreSQL, MySQL, MariaDB and SQL Server versions for 5.2 in the same place.
- Upgrade starting point: confirm the minimum Moodle version you must already run before upgrading to 5.2.
- Document root: the /public layout introduced in 5.1 carries forward, so keep the Nginx root pointed at /public.
Write the confirmed 5.2 minimums into your build sheet with the source and date, so the Ubuntu and database versions you pick can be traced back to them during review.
Moodle 4.5 is a long-term support release from 7 October 2024, with security support until 4 October 2027. It suits sites that are still on the 4.x line and need a stable base while they plan a staged move to a later release. Its requirements are different from the 5.x releases, so a 4.5 build should not reuse a 5.x server template.
- Support window: security support until 4 October 2027.
- PHP and database minimums: confirm the 4.5 values in its install documentation, because they are not set out in the release notes for the 5.x line.
- Document root: the /public requirement starts with 5.1, so follow the 4.5 install guidance for the web root.
- Staged upgrade: a move from 4.5 to a 5.x release has its own starting version and PHP floor, which you must check against the target release.
- Upgrade planning: count the upgrade steps and the server changes as separate work items in your plan.
Before you select a PHP version and an Ubuntu release for 4.5, confirm its extension list and database support in the 4.5 documentation, then record the target 5.x release and its floor in the same plan.
How to install the Nginx, PHP-FPM and Moodle stack in order
This sequence takes a bare Ubuntu server to a working Moodle site with the web root on /public, the database and dataroot kept outside the web root, and a verified admin login. Each step ends with a check you can run before moving on.
Confirm the target release and server minimums
Before installing anything, choose the Moodle release and check its requirements in the release notes. Moodle 5.1 requires 64-bit PHP 8.2 or later and PostgreSQL 15, MySQL 8.4, MariaDB 10.11 or SQL Server 2017 or later. Moodle 5.3 requires PHP 8.3 or later and PostgreSQL 17, among other minimums. Confirm the upgrade path from your starting version as well. Check: the PHP and database versions you plan to use appear in the release notes for your chosen release.
Install Nginx, PHP-FPM and required extensions
Install Nginx, PHP-FPM, the PHP command-line tools and the extensions listed in the Moodle install requirements for your release, including OPcache. Install your chosen database server in this step or connect to an existing one. Confirm the PHP build is 64-bit and the packages match the version you confirmed. Check: run
php -vto confirm the version,php -mto list loaded extensions,nginx -v, andsystemctl status php-fpm(the service name varies by PHP version) to confirm the service is running.Configure the PHP-FPM pool and php.ini values
Create or edit a PHP-FPM pool that runs as a dedicated user with its own socket, and set the php.ini values Moodle needs, including max_input_vars, memory limit, upload limits and time limits as the install documentation specifies for your release. Enable OPcache with settings suited to the code size. Confirm the exact max_input_vars value against Moodle's documentation for your release, since the environment check will flag a low value. Check: run
php-fpm -tto test the configuration, thenphp -i | grep max_input_varsto confirm the value the web pool uses.Create the database and user outside the web root
Create an empty database and a dedicated database user with full rights to that database only. Use the character set and collation the Moodle database requirements specify for your engine. Keep the credentials out of the web root; you will place them in config.php in a later step, and that file lives in the code directory, so restrict its permissions after install. Check: connect as the new user with the database client (for example
psqlormysql) and confirm you can create and drop a test table, then remove the test table.Download Moodle code and place it outside the web root
Obtain the Moodle code for your chosen release from the official source, either the GitHub repository tag or the release package, and extract it to a directory such as
/opt/moodleor a similar path that is not the Nginx document root. Verify the download against the checksum or tag published with the release. Set the code files to be owned by root or a deploy user and readable by the PHP-FPM user, so PHP can read them without being able to change them. Check: openversion.phpin the code directory and confirm the release number matches the release you planned.Create dataroot with the correct ownership
Create the moodledata directory outside the code directory and outside the web root. Set ownership to the PHP-FPM user and restrict permissions so other local users cannot read it. Dataroot holds uploaded files, caches and session data, so it must be writable by PHP and must not be served directly by Nginx. Confirm the path and permissions with your backup plan, since dataroot must be backed up alongside the database. Check: run
ls -ldon the directory to confirm owner and mode, then runsudo -u www-data touch /path/to/moodledata/test(substitute your PHP-FPM user) and remove the test file.Point Nginx at /public and run the CLI installer
Configure an Nginx server block whose root is the
publicdirectory inside the Moodle code, and pass PHP requests to the PHP-FPM socket for your pool. For Moodle 5.1 and later, the document root must point to/publicor the site may show directory listings or errors. Reload Nginx, then run the command-line installer from the code directory with the database details, admin account and site settings you agreed. The installer writesconfig.php. Check: runnginx -tbefore reloading, then request the site over HTTP from the server and confirm a Moodle response rather than a listing or PHP error.Schedule cron and verify the post-install checks
Add a cron entry or systemd timer that runs Moodle's cron script as the PHP-FPM user at the interval your release documentation recommends. Sign in as the site administrator and open the notifications page and the server environment page, and resolve every error and any warning that affects production. Confirm the site uses the public path and that the dataroot location is correct. Check: run the cron script once by hand and confirm it completes without errors, then confirm the admin notifications page reports no outstanding errors.
Only Nginx faces clients, and PHP-FPM reaches the database and dataroot from the private tier
The request starts at the client and enters Nginx, whose document root is the public directory of the Moodle code, not the folder above it. Nginx hands PHP requests to PHP-FPM over FastCGI, and PHP-FPM reads config.php from outside the web root before opening connections to the database server and writing uploads and caches to moodledata. Cron runs as a separate command-line caller on the same application code. Check that the web root is the public directory and that moodledata sits outside it.
Request path from Nginx through PHP-FPM to the database and dataroot, with cron as a separate caller.
Which PHP settings and extensions Moodle needs and why
Moodle's PHP layer decides whether large course forms save, whether uploads succeed and whether the site stays fast under load. The settings below interact, so change them together and verify each one on the same PHP-FPM pool that serves your site. Confirm every value against the installation requirements for your target release and your own load tests.
max_input_vars for large forms
PHP drops POST variables beyond max_input_vars, and large Moodle forms such as course editing, question banks and grade settings can submit more fields than the default allows. The failure is quiet: a form saves partially or shows a validation error on fields the user did not touch. Raise the value in the PHP-FPM pool configuration, then test the largest course and gradebook forms your teachers use. Confirm the minimum in the release installation requirements.
OPcache sizing and timestamps
OPcache stores compiled PHP so Moodle does not parse thousands of files on every request. Size opcache.memory_consumption and opcache.max_accelerated_files against the number of files in your code tree, including plugins, and monitor for cache restarts. Setting opcache.validate_timestamps to off gives the best throughput but means PHP never sees file changes until the cache is reset, so every upgrade and plugin change needs a planned PHP-FPM reload.
memory_limit and upload limits
memory_limit must cover the heaviest requests Moodle makes, such as backups, restores, large report builds and imports. Upload limits have to match in three places: upload_max_filesize and post_max_size in PHP, and the client_max_body_size directive in Nginx. A mismatch produces failures that look like Moodle errors. Set the values from your own backup and course file sizes, and confirm the minimums in the release requirements.
Required 64-bit PHP extensions
Moodle depends on a set of PHP extensions for database access, XML, image handling, internationalization, sessions and encryption. Missing or 32-bit builds stop the installer or cause failures only on specific pages. Install the extensions that match your database driver, run the environment check in the admin screens after install, and confirm the exact list and PHP version range against the release notes for the Moodle version you deploy.
- Minimum for 5.1
- PHP 8.2
Session and tmp paths
Sessions and temporary files need writable, private locations that PHP-FPM can reach but other pool users cannot read. Point session.save_path at a directory owned by the PHP-FPM user with restrictive permissions, and keep Moodle's tempdir inside dataroot or another private path. Shared or world-readable temp locations expose session data, and a full disk in these paths breaks logins and uploads. Plan monitoring and cleanup for both.
Where moodledata goes and how cron runs
Place moodledata outside the web root and make sure no Nginx location block can serve it. Moodle stores uploaded files, caches, session data written to disk, backups and temporary files there, and much of it is served through Moodle's own PHP code, not as static files. If the directory sits under the document root, a misconfigured location block or a directory listing can expose private course files directly. Create it as a sibling of the Moodle code directory, for example /var/moodledata, and set $CFG->dataroot in config.php to that absolute path. Confirm the path against the install guide for the release you deploy, because the web root rules changed in recent releases and the 5.1 notes require the server to point at the /public directory.
Ownership matters as much as location. The directory should belong to the PHP-FPM pool user (commonly www-data on Ubuntu) with mode 0700 or 0750, so PHP can read and write it while other local accounts and the web server's static file handling cannot. Do not make it world-readable to simplify a permissions error, and do not run the installer or cron as root, because files created by root later block the PHP-FPM user from writing them. Run sudo -u www-data php admin/cli/cron.php once after setup and check the resulting file owners. Keep the Moodle code read-only to the web user where your plugin workflow allows, and record which path holds writable data for your backup scope.
Cron is a scheduled CLI job, not a web request, and it must run as the same user that owns the dataroot. A system cron entry or systemd timer runs admin/cli/cron.php every minute. Each run executes due scheduled tasks, which include session and cache housekeeping, log and file cleanup, mail queue processing, forum digests, completion updates and plugin tasks. If cron stops, emails stop being sent, caches grow, and site administration shows a cron warning. Check the last run time in site administration after go-live, and alert on the absence of a run. Test the job as the correct user, and ask your plugin vendors which of their tasks need longer runtimes or separate scheduling. File sizing and NFS locking for dataroot are covered on the dataroot planning page.
Which post-install checks confirm the server is ready
What does the Moodle Site and environment report prove after installation?
The Site and environment report, found under Site administration, lists each server requirement Moodle checks, such as PHP version, required and recommended extensions, database version and the max_input_vars setting, and marks each as OK, warning or error. It proves that Moodle, running under the PHP-FPM pool you configured, can see the requirements it needs at the moment you open the page. It does not prove that the report is complete for your release, that OPcache is tuned for your traffic, or that backups and restores work. Confirm the environment checks against the requirements listed for your exact release, because minimums change between major versions. The Moodle releases page lists current support windows, and the 5.1 and 5.3 release notes list the PHP and database minimums for those versions.
How do I tell if the document root is wrong for Moodle?
Request the site's home page and a few deep paths, such as a plugin or admin URL, through the public hostname. If you see a directory listing of Moodle's source files, or a raw PHP error about missing config or paths, the web server document root is pointing at the main Moodle folder instead of public. From Moodle 5.1 the document root must point to the new public directory, so check the root directive in your Nginx server block and reload the service after any change. This check proves that the public entry point is served correctly. It does not prove that the rest of the stack, such as PHP-FPM socket permissions or the routing rules, is correct, so run the environment report as well.
How do I confirm cron is running for Moodle?
Open Site administration, then the scheduled task overview, and check the last run time for the core cron tasks and the Cron status in the environment or notifications area. A recent last-run time, updated on the schedule you set in the system cron job, shows that the scheduler starts and completes at least one run. It does not prove that every task succeeds, that the job runs as the web server user, or that it survives a server reboot. Look for failed tasks in the task log, and confirm the cron entry in the crontab of the account that owns the Moodle files. Your operations team should confirm the interval against Moodle's cron documentation for your release.
What should I verify for HTTPS and HSTS before go-live?
Confirm that the site loads only over HTTPS, that HTTP requests redirect to HTTPS, that the certificate chain is complete and trusted by the browsers your users run, and that the wwwroot value in config.php uses ` Check that the Strict-Transport-Security header is present on HTTPS responses with the max-age you chose, using your browser developer tools or a header check tool. These checks prove that transport is encrypted and the header is sent. They do not prove that HSTS preload is safe for your domain, that internal links avoid mixed content, or that your certificate renewal process will work next quarter. Confirm the header policy with your security team before setting a long max-age.
How do I test that Moodle email delivery works?
Send a test message from Moodle's outgoing mail configuration page, or create a test user with a real mailbox you control and trigger a password reset. Confirm the message arrives, check the headers for the sender address and the relay that handled it, and review the Moodle logs for any SMTP errors. A delivered test message proves that Moodle can reach your relay and that the relay accepts the sender. It does not prove that SPF and DKIM are aligned for your domain, that bounces are processed, or that mail to external providers lands in the inbox rather than spam. Those points need DNS checks and a bounce handling review, which the outgoing email topic covers in more depth.
Can I run these post-install checks myself, or do I need a partner?
Most of these checks need only administrator access to Moodle, shell access to the server, and a browser, so an experienced platform team can run them without outside help. A partner adds value when you want the checks written into a repeatable runbook, when the configuration has to be reviewed against your security baseline, or when your compliance team needs dated evidence of the results. Engagements of this kind are fixed-scope, with the checks, deliverables and timeline agreed in writing before work starts, and quotes follow from that scope. The cost depends on how many environments you have, how much of the stack you want documented, and whether you need a retest after fixes.
Which checks are still needed after the environment report is green?
A green environment report is necessary but not sufficient. Add these to the review: a successful restore of a backup into a separate environment, confirmation that the dataroot is outside the web root and not served by Nginx, a test of uploads and file downloads, a check of PHP error logs for warnings during a sample session, and a review of the admin settings that control the web root and file permissions. These checks show that the platform can be recovered and that files are protected. They do not replace a security review or a load test, which need their own scope and evidence.
Security settings to lock down on the Nginx and PHP-FPM tier
Most Moodle exposure on a self-hosted Ubuntu server comes from the web and PHP tier, not from Moodle code itself. The cards below cover the server settings that decide what a browser, another local user or an attacker can reach, and they connect to one question: which files can the web server and PHP process actually read and execute?
Block PHP and config outside /public
Since Moodle 5.1 the web server document root must be the public directory, not the main Moodle folder. If Nginx still points at the parent folder, config.php, library code and installer scripts can be reachable, and directory listings or errors may appear. Confirm the root directive ends in /public, then request config.php and a sample library path directly and expect a refusal or a 404.
Keep moodledata out of reach
The moodledata directory stores uploaded files, caches and session data, and it must sit outside the web root. Make it owned by the PHP-FPM pool user with no read access for other local accounts, typically mode 0700 or a tightly scoped group. Test with a plain HTTP request to a known file path under the data directory, which should never be served.
Separate PHP-FPM pool users
Run the Moodle pool under a dedicated system user, not www-data shared with other sites on the same host. Give that user write access only to moodledata and the cache or temp paths Moodle needs, and make the code tree owned by a deploy user with read-only access for the pool. A compromise of one site then does not hand over every site's files on the box.
Lock TLS and HTTP headers
Moodle carries logins, grades and personal data, so the Nginx server block should offer only current TLS versions, use strong cipher suites and redirect all HTTP to HTTPS. Set Strict-Transport-Security only after you confirm every subdomain serves HTTPS. Ask your security team to verify the result with an external scanner before go-live.
Tie patching to release support dates
Plan patch windows around Moodle's support dates rather than ad hoc. Moodle 5.1 has security support until 19 April 2027, and Moodle 5.2 has security support until 4 October 2027, so a site on 5.1 must move before that first date. Keep PHP and the database on versions that the Moodle release notes still list, and reapply the Nginx and PHP-FPM configuration after each upgrade.
Moodle releasesKeep secrets out of config.php
config.php holds the database password, the data root path and often SMTP and API credentials. Keep the file readable only by the deploy user and the pool user, and avoid committing it to version control. Where your environment allows, pull credentials from environment variables or a secrets store at deploy time. Moodle-side controls, such as the configuration lock settings, are covered in the Moodle security hardening pages.
What installing Moodle on Ubuntu costs and what the work needs from you
What drives the cost of installing Moodle on Ubuntu?
Scope and environment drive the cost more than the installation steps themselves. The base server build is the smaller part; the larger variables are the number of environments (production, staging and a test copy), whether the server sits in a cloud account, a data center or an air-gapped network, how many integrations need configuring at install time (single sign-on, email relay, storage), and how much hardening and evidence your security or compliance team expects. Ask for a quote that lists each environment, each integration and each evidence item as a separate line, so you can see what changes the price if you remove or add one.
How long does a Moodle server build on Ubuntu take?
The duration depends on scope, so no fixed figure applies here. A single production server with a documented stack can be a short engagement, while a build with staging, load balancing, external database and integrations takes longer because each adds design, testing and change windows. Your release choice also matters: Moodle 5.1 and 5.3 have different server minimums, so confirm the target release before the timeline is agreed. Ask for a written schedule with milestones for environment handover, test sign-off and go-live.
Can our internal team install Moodle on Ubuntu without a partner?
Yes, if your team already runs Nginx, PHP-FPM and a supported database and has time to test the result. The work is standard system administration, but the details are easy to get wrong: the web server document root must point to the /public directory from Moodle 5.1 onward, max_input_vars and OPcache need tuning, and the dataroot must sit outside the web root with correct permissions. A partner adds value when your team lacks that experience, needs a documented and repeatable build, or must pass a security review before go-live. Many organizations split the work, with the partner building the server and the internal team taking over operations.
What does DeployOpen need from our team before the build?
DeployOpen needs access and decisions before work starts. Typically this means: server or cloud account access in your environment, a named contact who approves changes, change windows for production work, the Moodle release you intend to run, the database engine and version you have chosen, DNS records for the site name, and a TLS certificate or the means to issue one. Your team should also confirm where the dataroot will live and how backups are taken. The exact list is agreed in the written scope, so ask for it before signing.
What is one-time work and what recurs after a Moodle server goes live?
The installation, hardening, initial configuration and post-install checks are one-time work. Recurring work includes operating system and PHP patching, Moodle minor point releases, moving to new major releases before their support ends, certificate renewal, database and dataroot backup checks, and monitoring that cron runs on schedule. Moodle minor releases arrive every two months, so budget for a regular maintenance cycle rather than treating the build as finished. Ask whether the quote includes a first upgrade and an ongoing support retainer, and what each one covers.
When is a managed Moodle host a better fit than a self-built Ubuntu server?
A managed host is usually the better fit when you do not need to control the infrastructure, the data must not leave a specific jurisdiction you can already meet through a provider, and your team has no capacity for patching and monitoring. Moodle offers managed hosting through MoodleCloud and Moodle Partners, which shifts operations to the provider. Choose a self-built Ubuntu server when you must run in your own data center or air-gapped network, need custom PHP or web server settings, or must keep evidence for your own compliance team. Compare the two on operations responsibility, data location and exit options, not only on monthly cost.
What should we ask for in a written quote for this work?
Ask for a quote tied to a written scope that lists the deliverables, the environments, the Moodle release and database version, the integrations included, the hardening baseline, the handover documents and the post-install checks. Confirm who provides the server, who holds the administrator credentials at handover, what happens if a change window slips, and what is excluded, such as custom plugins, theme work or migration of existing courses. Ask how recurring patching and upgrades would be priced and whether a retainer is offered. DeployOpen agrees scope, deliverables and timelines in writing before work starts, so the quote should match that document.
How DeployOpen scopes, builds and supports a Moodle server
DeployOpen plans, installs and hardens self-hosted Moodle inside your own cloud accounts, data centers or air-gapped networks, starting from a written scope. The server work described on this page is delivered as part of that scope, with documentation and a supported operating path handed to your team.
How we scope
- Engagements are fixed-scope, with the Moodle version, PHP and database targets agreed in writing before work starts.
- The written scope names the Ubuntu release, Nginx and PHP-FPM layout, dataroot location, cron approach and the post-install checks to be delivered.
- Ask for the scope to state which Moodle release you will run, since minimum PHP and database versions differ between releases.
How we build
- Nginx is configured with the document root pointed at the /public directory for supported Moodle releases, with PHP-FPM pools sized for your expected load.
- Required PHP extensions, max_input_vars and OPcache settings are applied and verified against the Moodle environment check before users are onboarded.
- Dataroot is placed outside the web root with restricted permissions, and a cron job is configured and tested end to end.
How we hand over
- Handover includes a written record of server configuration, file paths, service accounts and the post-install check results.
- Your team receives the steps to run upgrades, restart PHP-FPM and Nginx, and confirm cron is running after maintenance.
- Confirm with DeployOpen which documents, configuration files and test evidence are included in the handover before signing the scope.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after the initial build is handed over.
- Support can cover patching the operating system, PHP and Moodle minor releases, and re-running the environment checks after changes.
- Ask for the retainer terms in writing, including response expectations and which changes fall inside the retainer and which need a new scope.

