Skip to content

Deploying a Moodle App

Introduction

Moodle is an open-source learning management system built on PHP. Deploying Moodle with a Dockerfile on Klutch.sh provides reproducible builds, managed secrets, and persistent storage for configuration and course data—all configured from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample usage, and production tips.


Prerequisites

  • A Klutch.sh account (sign up)
  • A GitHub repository containing your Moodle code and Dockerfile (GitHub is the only supported git source)
  • A MySQL/MariaDB database (deploy as a Klutch.sh TCP app on port 8000 and connect on 3306)
  • SMTP credentials for notifications
  • Domain ready for your Moodle site

For onboarding, see the Quick Start.


Architecture and ports

  • Moodle runs on PHP/Apache; set the internal container port to 8080 and choose HTTP traffic.
  • Database runs separately on TCP; connect on 3306.
  • Persistent storage is required for Moodle data, config, and cache.

Repository layout

moodle/
├── Dockerfile # Must be at repo root for auto-detection
├── config.php # Generated/edited; keep secrets out of Git
├── moodledata/ # Data directory (persist)
├── cache/ # Cache (persist recommended)
└── README.md

Keep secrets out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Validate locally before pushing to GitHub:

Terminal window
docker build -t moodle-local .
docker run -p 8080:8080 --env-file .env moodle-local

Dockerfile for Moodle (production-ready)

Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):

FROM php:8.1-apache
ENV APACHE_HTTP_PORT_NUMBER=8080
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y --no-install-recommends \
libpng-dev libjpeg-dev libzip-dev libicu-dev libxml2-dev unzip git \
&& docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install gd mysqli zip intl xmlrpc soap opcache \
&& a2enmod rewrite \
&& sed -i 's/80/${APACHE_HTTP_PORT_NUMBER}/g' /etc/apache2/ports.conf /etc/apache2/sites-available/000-default.conf \
&& rm -rf /var/lib/apt/lists/*
COPY . .
RUN mkdir -p moodledata cache && chown -R www-data:www-data /var/www/html
EXPOSE 8080
CMD ["apache2-foreground"]

Notes:

  • Add more PHP extensions if your plugins require them (e.g., ldap, imap).
  • Keep moodledata/ and cache/ writable; mount them as volumes.

Environment variables (Klutch.sh)

Set these in Klutch.sh before deploying:

  • MOODLE_URL=https://example-app.klutch.sh
  • DB_HOST=<db-host>
  • DB_PORT=3306
  • DB_NAME=<db-name>
  • DB_USER=<db-user>
  • DB_PASS=<db-password>
  • DB_TYPE=mysqli
  • APACHE_HTTP_PORT_NUMBER=8080
  • SMTP: SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_SECURE (e.g., tls)

If you deploy without the Dockerfile and need Nixpacks overrides (PHP):

  • NIXPACKS_PHP_VERSION=8.1
  • NIXPACKS_START_CMD=apache2-foreground

Attach persistent volumes

In Klutch.sh storage settings, add mount paths and sizes (no names required):

  • /var/www/html/moodledata — course files, user data, and caches.
  • /var/www/html/cache — application cache (optional but recommended).
  • /var/www/html/config.php — configuration; include in a small volume if you keep it outside the image.

Ensure these paths are writable inside the container.


Deploy Moodle on Klutch.sh (Dockerfile workflow)

  1. Push your repository—with the Dockerfile at the root—to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  3. Select HTTP traffic and set the internal port to 8080.
  4. Add the environment variables above, including database and SMTP settings.
  5. Attach persistent volumes for /var/www/html/moodledata, /var/www/html/cache, and optionally /var/www/html/config.php, sizing for your content and cache.
  6. Deploy. Complete the Moodle web installer at https://example-app.klutch.sh and connect to your database.

Sample usage

Basic reachability:

Terminal window
curl -I https://example-app.klutch.sh

After installation, you can trigger Moodle’s CLI tasks via a one-off container exec (e.g., cron replacements) if needed.


Health checks and production tips

  • Add an HTTP probe to / or a simple status page once configured.
  • Enforce HTTPS at the edge; forward internally to port 8080.
  • Use strong DB/SMTP secrets stored in Klutch.sh and rotate them regularly.
  • Monitor volume usage for moodledata; resize before it fills.
  • Keep PHP and Moodle updated; test upgrades in staging first.

Moodle on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root, port 8080 configured, and MySQL/MariaDB connected, you can deliver a robust LMS without extra YAML or workflow overhead.