moodle-docker

Moodle installation using docker

Clone moodle git repo to www

git clone -b MOODLE_401_STABLE https://github.com/moodle/moodle.git www

Create dockcer-compose.yaml file in project directory

# file: /srv/moodle.example.com/docker-compose.yml
# purpose:  to run moodle along with mysql database

version: "2.4"

name: moodle-example-com

services:
  moodle:
   image: rsubr/php-apache-ubuntu:jammy
   container_name: moodle.example.com
   restart: always

   mem_limit: 4G

   volumes:
     - /etc/localtime:/etc/localtime:ro
     - ./www:/var/www/html
     - ./moodledata:/var/www/moodledata
     - ./etc/apache2/mods-enabled/mpm_prefork.conf:/etc/apache2/mods-enabled/mpm_prefork.conf:ro
     - ./etc/php/99-local.ini:/etc/php/8.1/apache2/conf.d/99-local.ini:ro

   ports:
     - 8000:80

   labels:
      - com.centurylinklabs.watchtower.enable=true
      - traefik.enable=true
      - traefik.http.routers.moodle.rule=Host(`moodle.example.com`)
      - traefik.http.routers.moodle.tls=true

   depends_on:
     mariadb:
        condition: service_healthy

  mariadb:
    image: mariadb:11
    container_name: mariadb-moodle.example.com
    restart: always

    mem_limit: 2G

    environment:
      - MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1
      - MARIADB_USER=${MARIADB_USER}
      - MARIADB_PASSWORD=${MARIADB_PASSWORD}
      - MARIADB_DATABASE=${MARIADB_DATABASE}


    volumes:
      - ./database:/var/lib/mysql

    labels:
      - com.centurylinklabs.watchtower.enable=true

    healthcheck:
      test: healthcheck.sh --connect --innodb_buffer_pool_loaded --innodb_initialized
      interval: 5s
      timeout: 180s
      retries: 3

  moodle_runner:
    image: rsubr/php-apache-ubuntu:jammy
    container_name: moodle.example.com_runner
    restart: always

    mem_limit: 1G

    entrypoint: [ "/entrypoint.sh" ]

    volumes:
      - /etc/localtime:/etc/localtime:ro      
      - ./www:/var/www/html
      - ./moodledata:/var/www/moodledata
      - ./etc/apache2/mods-enabled/mpm_prefork.conf:/etc/apache2/mods-enabled/mpm_prefork.conf:ro
      - ./etc/php/99-local.ini:/etc/php/8.1/apache2/conf.d/99-local.ini:ro 
      - ./entrypoint.sh:/entrypoint.sh 

Create 'entrypoint.sh file in project directory

#!/bin/bash

# Run moodle scheduled jobs periodically

# Sleep interval in seconds
INTERVAL=60

# Run first iteration immediately, then sleep and loop
/usr/bin/php /var/www/html/admin/cli/cron.ph > /tmp/moodle.bit.lan-cron.log 2>&1

while sleep ${INTERVAL} ; do
    /usr/bin/php /var/www/html/admin/cli/cron.php > /tmp/moodle.bit.lan-cron.log 2>&1
done

create .env file in project directory

COMPOSE_PROJECT_NAME=moodle
MARIADB_USER=moodle
MARIADB_PASSWORD=moodle
MARIADB_DATABASE=moodle

Create a www/config.php file



<?php  // Moodle configuration file

unset($CFG);
global $CFG;
$CFG = new stdClass();

$CFG->dbtype    = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'mariadb';
$CFG->dbname    = 'moodle';
$CFG->dbuser    = 'moodle';
$CFG->dbpass    = 'moodle';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbport' => 3306,
  'dbsocket' => '',
  'dbcollation' => 'utf8mb4_general_ci',
);

$CFG->wwwroot   = 'https://moodle.example.com';
$CFG->dataroot  = '/var/www/moodledata';
$CFG->admin     = 'admin';

$CFG->directorypermissions = 0777;

require_once(__DIR__ . '/lib/setup.php');

// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!

Moodle shows the following error

Call to undefined function course_overviewfiles_options()  This error is resolved by clearing the cache, but after clearing the cache the error appears  Exception - Call to undefined function core_login_get_return_url()  After clearing the cache again the first error returns after a short time

The reason is lib.php file not called properly in all php files.

Update ./lib.php instead of lib.phpin www directory.

References

  1. Moodle Step-by-step Installation Guide