How to Install Moodle 5.3 LTS on Debian 13 with Nginx and MariaDB
Moodle 5.3 LTS needs PHP 8.3+, sodium and MariaDB 11.4+. Debian 13 provides all of it; this guide covers nginx, the CLI installer, cron and updates.
Moodle is an open source learning management system for running online courses. This guide installs Moodle 5.3, the current long-term support (LTS) release, on Debian 13 with nginx, PHP-FPM and MariaDB. At the end you will have a working Moodle site served over HTTPS, with the scheduled-task runner in place and an upgrade path through Git.
Moodle 3.3 and CentOS 7 are both long out of support (CentOS 7 reached end of life in June 2024). Moodle 5.3 was released in October 2026 and receives security fixes until October 2029; the previous LTS, Moodle 4.5, is supported until October 2027.
Why Debian 13 and not the RHEL 9 family
Moodle itself does not prescribe a Linux distribution, but 5.3 has strict minimum versions:
| Component | Moodle 5.3 requirement | Debian 13 ships |
|---|---|---|
| PHP | 8.3 or 8.4, 64-bit, with the sodium extension | 8.4 |
| MariaDB | 11.4 or later | 11.8 |
| MySQL | 8.4 or later | not packaged |
| PostgreSQL | 17 or later | 17 |
Debian 13 meets all of this from its own repositories. The successors of CentOS 7 do not: AlmaLinux 9 and Rocky Linux 9 offer PHP 8.3 as a module stream, but their AppStream repository has no php-sodium package, so you would need a third-party PHP repository. Ubuntu 24.04 has a suitable PHP 8.3 but its MariaDB, MySQL and PostgreSQL packages are all older than the minimums above, and Ubuntu 26.04 ships PHP 8.5, which the Moodle 5.3 release notes do not list. If you have to stay on one of those systems, check the Moodle 5.3 release notes and bring the missing component from the vendor's own repository.
Requirements
- A Debian 13 server and a
sudouser (the examples usedeploy). - A DNS record such as
moodle.example.compointing to the server, and ports 80 and 443 open.
Step 1: Install nginx, PHP and MariaDB
sudo apt update
sudo apt install -y nginx mariadb-server php-fpm php-cli php-mysql php-xml php-mbstring \
php-curl php-zip php-gd php-intl php-soap git composer certbot python3-certbot-nginxMoodle refuses to install unless PHP's max_input_vars is at least 5000. Set it, together with larger upload limits, in a separate file that applies to both PHP-FPM and the command line:
sudo tee /etc/php/8.4/mods-available/moodle.ini > /dev/null <<'EOF'
max_input_vars = 5000
upload_max_filesize = 100M
post_max_size = 100M
EOF
sudo phpenmod moodle
sudo systemctl restart php8.4-fpmStep 2: Create the database
Open the MariaDB shell as root:
sudo mariadbCreate a utf8mb4 database and a dedicated account. Replace the password.
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'CHANGE_ME';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER ON moodle.* TO 'moodleuser'@'localhost';
EXIT;Step 3: Get the Moodle code
Installing from Git makes later updates a single git pull. The code is owned by your own user, not by the web server, so that a compromised PHP process cannot modify it:
sudo mkdir /var/www/moodle
sudo chown $USER: /var/www/moodle
git clone --depth 1 -b MOODLE_503_STABLE https://github.com/moodle/moodle.git /var/www/moodleInstall the PHP libraries with Composer. In Moodle 5.3 this step is still optional for the core features, but some newer features depend on it and it becomes mandatory in Moodle 6.0:
cd /var/www/moodle
composer install --no-dev --classmap-authoritativeCreate the data directory for uploaded files, caches and sessions. It must be writable by the web server and must not be inside the web root:
sudo mkdir /var/moodledata
sudo chown www-data:www-data /var/moodledata
sudo chmod 750 /var/moodledataStep 4: Configure nginx
Since Moodle 5.1 only the public subdirectory may be exposed to the web, and requests for paths that are not files are handed to the Moodle router, r.php. Moodle also passes file paths after the script name (for example /pluginfile.php/12/course/image.png), so the PHP location has to split that path off. Create /etc/nginx/sites-available/moodle:
server {
listen 80;
server_name moodle.example.com;
root /var/www/moodle/public;
index index.php;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /r.php$is_args$args;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
}Enable the site, then let Certbot obtain a certificate and add the HTTPS configuration:
sudo ln -s /etc/nginx/sites-available/moodle /etc/nginx/sites-enabled/moodle
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx
sudo certbot --nginx -d moodle.example.comStep 5: Run the installer
The command-line installer creates config.php and the database tables. It must run as the web server user, which needs permission to create that one file, so hand over the top-level directory for the duration of the installation:
sudo chown www-data /var/www/moodle
sudo -u www-data php /var/www/moodle/admin/cli/install.php \
--lang=en \
--chmod=2770 \
--wwwroot=https://moodle.example.com \
--dataroot=/var/moodledata \
--dbtype=mariadb \
--dbname=moodle \
--dbuser=moodleuser \
--dbpass='CHANGE_ME' \
--fullname="Example Learning" \
--shortname="Example" \
--adminuser=admin \
--adminpass='CHANGE_ME_TOO' \
--adminemail=admin@example.com \
--non-interactive \
--agree-licenseThe installation takes a few minutes. Afterwards, take the directory back and make the configuration file readable by the web server only:
sudo chown $USER /var/www/moodle
sudo chown root:www-data /var/www/moodle/config.php
sudo chmod 640 /var/www/moodle/config.phpIf you prefer the browser-based installer, do the chown www-data step, open https://moodle.example.com and follow the pages instead of running install.php.
The nginx configuration above already routes requests through r.php, so tell Moodle that the router is configured. Edit /var/www/moodle/config.php with sudo and add this line above the final require_once line:
$CFG->routerconfigured = true;Step 6: Set up cron
Moodle depends on a scheduled-task runner for email, course completion, clean-up and much more. It should run every minute as the web server user:
sudo crontab -u www-data -eAdd this line:
* * * * * /usr/bin/php /var/www/moodle/admin/cli/cron.php >/dev/nullVerify the installation
Sign in at https://moodle.example.com with the administrator account from step 5, then check two pages:
- Site administration > Server > Environment lists every server check; all required items must show OK.
- Site administration > Notifications warns if cron has not run recently or if the data directory is reachable from the web.
You can also run cron once by hand and watch for errors:
sudo -u www-data php /var/www/moodle/admin/cli/cron.phpUpdating Moodle
Minor releases on the 5.3 branch are published regularly. Back up the database, /var/moodledata and config.php first, then:
sudo -u www-data php /var/www/moodle/admin/cli/maintenance.php --enable
cd /var/www/moodle
git pull
composer install --no-dev --classmap-authoritative
sudo -u www-data php /var/www/moodle/admin/cli/upgrade.php --non-interactive
sudo -u www-data php /var/www/moodle/admin/cli/maintenance.php --disableA database backup can be taken with sudo mariadb-dump --single-transaction moodle > moodle.sql.
Frequently asked questions
Should I install 5.3 or stay on 4.5?
For a new site, install 5.3: it is the newest LTS and has three years of security support ahead of it. Moodle 4.5 only makes sense if a plugin you depend on has not been released for the 5.x series yet. A direct upgrade to 5.3 requires Moodle 4.4 or later.
The site shows a directory listing or a 404 for every page. What is wrong?
The web server's document root points to the Moodle directory instead of its public subdirectory, or the fallback to r.php is missing. Both were introduced with Moodle 5.1; configurations written for 4.x and 5.0 do not work unchanged.
Where do plugins go?
Under /var/www/moodle/public, in the same relative paths as before the restructuring: an activity module goes to public/mod/, a block to public/blocks/, a theme to public/theme/. Because the web server cannot write to the code directory in this setup, unpack plugins as your own user and then visit Site administration > Notifications to run their installation.
Can I use PostgreSQL instead of MariaDB?
Yes. Debian 13 ships PostgreSQL 17, which meets the minimum. Install postgresql and php-pgsql, create a UTF-8 database owned by a dedicated role and pass --dbtype=pgsql to the installer.