TECHNICAL GUIDE

Use this guide as an implementation reference. Validate commands, policies and version-specific behaviour in a lab before applying changes to production systems.

1. Plan the Moodle server

Moodle requires a web server, supported PHP runtime, database and writable data directory outside the web document root. This example uses Ubuntu 24.04 LTS with Apache, PHP 8.3 and MariaDB 10.11 for a Moodle release whose requirements support that combination. Always check the requirements page for the exact Moodle branch before installing; Moodle 5.3 has newer database and PHP requirements and may not work with Ubuntu 24.04 default MariaDB.

Use a domain such as learn.example.edu, configure DNS, and size CPU, RAM and storage for concurrent learners, course files and backups.

2. Update Ubuntu and install Apache, MariaDB and PHP

sudo apt update && sudo apt full-upgrade -y\nsudo apt install -y apache2 mariadb-server mariadb-client \\\n  php8.3 libapache2-mod-php8.3 php8.3-cli php8.3-common \\\n  php8.3-curl php8.3-gd php8.3-intl php8.3-mbstring \\\n  php8.3-mysql php8.3-xml php8.3-zip php8.3-soap \\\n  php8.3-ldap php8.3-opcache php8.3-readline \\\n  graphviz aspell ghostscript git unzip\nsudo systemctl enable --now apache2 mariadb\nphp -v

Check the Moodle requirements page for additional PHP extensions and supported database versions. Do not install both Apache and Nginx for this single-web-server example.

3. Secure MariaDB and create a Moodle database

sudo mariadb-secure-installation\nsudo mariadb

At the MariaDB prompt, create a dedicated database and user. Use a unique strong password, and choose the character set and collation recommended by your Moodle release.

CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\nCREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'REPLACE_WITH_STRONG_PASSWORD';\nGRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;

Keep the database bound to localhost unless a separate database server is intentionally used and protected by network ACLs.

4. Create the protected moodledata directory

The moodledata directory must not be inside the public web root. It contains uploaded course files, caches and other data that must not be directly downloadable through Apache.

sudo mkdir -p /var/moodledata\nsudo chown -R www-data:www-data /var/moodledata\nsudo chmod 770 /var/moodledata

5. Download Moodle code

For production, use the official Moodle release archive or the documented Git stable branch. Pin the release and verify its checksum/signature when provided.

cd /tmp\n# Download the release archive from https://download.moodle.org/\n# Replace the URL below with the exact release archive you selected.\nsudo mkdir -p /var/www/moodle\nsudo tar -xzf moodle-latest-*.tgz -C /var/www/\nsudo chown -R root:root /var/www/moodle\nsudo find /var/www/moodle -type d -exec chmod 755 {} \\;\nsudo find /var/www/moodle -type f -exec chmod 644 {} \\;

Do not blindly use a wildcard if multiple archives are present. Confirm the extracted directory and release version before continuing.

6. Configure the Apache virtual host

sudo nano /etc/apache2/sites-available/moodle.conf

Use a virtual host similar to the following, replacing the hostname and checking the PHP module version installed on your system.

<VirtualHost *:80>\n  ServerName learn.example.edu\n  DocumentRoot /var/www/moodle\n  <Directory /var/www/moodle>\n    Options FollowSymLinks\n    AllowOverride None\n    Require all granted\n    DirectoryIndex index.php\n  </Directory>\n  <FilesMatch \\.php$>\n    SetHandler application/x-httpd-php\n  </FilesMatch>\n  ErrorLog ${APACHE_LOG_DIR}/moodle_error.log\n  CustomLog ${APACHE_LOG_DIR}/moodle_access.log combined\n</VirtualHost>
sudo a2dissite 000-default.conf\nsudo a2ensite moodle.conf\nsudo apache2ctl configtest\nsudo systemctl reload apache2

7. Run the Moodle web installer

Open http://learn.example.edu and follow the installer. Enter the protected data directory /var/moodledata, select MariaDB/MySQL, and provide the database name, user and password created earlier. Set the administrator account with a unique password and a monitored email address.

If the installer reports a missing PHP extension or an unsupported database version, stop and correct the platform requirement rather than bypassing the environment check.

8. Configure HTTPS and Moodle cron

Once DNS points to the server, install Certbot and issue a certificate:

sudo apt install -y certbot python3-certbot-apache\nsudo certbot --apache -d learn.example.edu\nsudo apache2ctl configtest

Moodle's scheduled tasks must run regularly. Add a cron entry for the Apache service account:

sudo crontab -u www-data -e
* * * * * /usr/bin/php /var/www/moodle/admin/cli/cron.php >/dev/null

Confirm the PHP CLI version matches the web runtime. Configure outbound SMTP in Moodle for password resets and notifications.

9. Production hardening and backups

  • Keep moodledata outside the document root and restrict its permissions.
  • Disable public directory listing and remove unused sample files.
  • Use HTTPS only and secure administrator accounts with MFA where available.
  • Set PHP upload and memory limits based on course requirements.
  • Back up the database, moodledata and code/configuration as a coordinated set.
  • Test restore procedures and monitor cron completion, disk usage and mail delivery.

Official references

Conclusion

A production Moodle service is more than a successful web installer. Protect moodledata, run cron every minute, use a supported PHP/database combination, enable HTTPS and test coordinated backups before onboarding learners.

Found this useful?