Moodle™ 5.1 put the web tree in public/. $CFG->dirroot is now that public/ directory. $CFG->root is the install root above it. $CFG->dataroot did not move. If nginx root still points at the install root, you are serving files Moodle spent a release cycle hiding.
This is a different failure from a dataroot that sits on the public hostname. Dataroot is student files. A wrong 5.1 document root is source: vendor/, node_modules/ leftovers, config.php, composer.json, .git, upgrade scripts, and every PHP file that used to sit next to index.php.
The official note is on moodledev.io. Operators who upgraded the code and not the vhost still pass a homepage screenshot.
Prove where the document root actually is
From the host, not from Moodle's GUI:
# what PHP thinks php -r 'define("CLI_SCRIPT", true); require "config.php"; echo "root=".$CFG->root."\n"; echo "dirroot=".$CFG->dirroot."\n"; echo "wwwroot=".$CFG->wwwroot."\n"; echo "dataroot=".$CFG->dataroot."\n";' # what nginx thinks sudo nginx -T 2>/dev/null | grep -E 'server_name|root |alias ' | head -40 $CFG->dirroot should end in /public. The nginx root (or Apache DocumentRoot) should be that same path. $CFG->root should be one directory up. $CFG->dataroot should still be outside both.
Then ask the public hostname for files that must 404 after 5.1:
HOST=https://lms.example.org for p in \ /config.php \ /composer.json \ /composer.lock \ /package.json \ /version.php \ /lib/setup.php \ /vendor/autoload.php \ /.git/HEAD \ /README.md \ /admin/cli/install.php \ /public/config.php do code=$(curl -sI -o /dev/null -w '%{http_code}' "$HOST$p") echo "$code $p" done On a correct 5.1 vhost the status column should look like this:
| Path | Expect |
| /config.php | 404 (config.php lives above public/) |
| /composer.json | 404 |
| /vendor/autoload.php | 404 |
| /.git/HEAD | 404 |
| /lib/setup.php | 404 (lib/ is not under public/) |
| /index.php | 200 |
| /pluginfile.php | 303 or 200 (the script moved into public/) |
A 200 on /config.php or /vendor/autoload.php after a 5.1 upgrade is the vhost you did not finish. config.php on a 200 is often <?php plus a redirect, or a blank, or the real file. The web server is reading a path Moodle no longer treats as public.
Apache is the same test with a different directive. DocumentRoot must be the public/ directory. A DocumentRoot of /opt/moodle plus an Alias /public /opt/moodle/public still serves /config.php from the parent. Set DocumentRoot /opt/moodle/public and drop the alias.
What the restructure actually moved
Moodle did not invent a new product. It split one tree into two:
-
$CFG->root— the git checkout / zip extract. Composer,node_modulesif you build there,config.php, CLI admin, PHPUnit. -
$CFG->dirroot—public/. This is the only directory the web server should see.index.php,pluginfile.php,draftfile.php, the rewrittenlib/copies that must stay web-reachable.
pluginfile.php still lives at /pluginfile.php on the public hostname, because it sits in public/pluginfile.php. A location regex you wrote for 4.5 still matches. The SCRIPT_FILENAME must now resolve inside public/. If it still points at the 4.x path, php-fpm 404s or runs an old copy you forgot to delete.
Dataroot is unchanged. Do not move it into public/ to “keep everything together”. That is the 2014 misconfig with a new folder name.
nginx sketch that matches 5.1
root /opt/moodle/public; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ ^/pluginfile\.php { include fastcgi_params; fastcgi_pass unix:/run/php/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_split_path_info ^(.+\.php)(/.*)$; } location ~ [^/]\.php(/|$) { include fastcgi_params; fastcgi_pass unix:/run/php/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_split_path_info ^(.+\.php)(/.*)$; } $document_root is /opt/moodle/public. A SCRIPT_FILENAME of /opt/moodle/pluginfile.php is the 4.x leftover.
If you terminate TLS on a proxy and php-fpm sits behind it, fastcgi_param HTTPS on; still matters. 5.1 did not fix a vhost that generates http:// $CFG->wwwroot links.
Two leftover traps
The old tree is still on disk next to public/. After the upgrade, /opt/moodle/lib/setup.php still exists. It is not supposed to be reachable. If root is /opt/moodle, it is reachable. Delete is the wrong first move; point root at public/ first, then decide what the deploy artefact is allowed to keep.
A second vhost still serves the install root. Staging, a leftover Apache vhost, a container that bind-mounts the checkout at /var/www/html. Curl the public hostname, and curl the origin IP with Host: set. I have seen the proxy look correct and the origin still serve /vendor/.
Check it the week after go-live
Config.php, composer.lock, and .git/HEAD are the three curls to keep next to the upgrade ticket. Re-run them after the next plugin zip, after the next theme deploy, after someone “temporarily” points an extra server at the checkout.
I built GuardLMS to notice when those paths come back. Disclosure: I am the founder. The curls above do not require it. The restructure guide is Moodle’s.

