Skip to content

knowmics-lab/moodle-development

Repository files navigation

Moodle Docker Compose Development Stack

A Docker Compose setup for Moodle 4.5 development environment with MySQL 8.0, pre-installed plugins, and easy plugin management.

Features

  • Moodle 4.5 (built from official download)
  • PHP 8.2 + Apache web server
  • MySQL 8.0 database
  • No Docker volumes - all data stored on host filesystem via path mappings
  • 13 pre-installed plugins ready to use
  • Easy plugin installation - add plugins without rebuilding the image
  • Development-friendly - error reporting enabled, hot-reload support

Prerequisites

  • Docker Engine 20.10+
  • Docker Compose 2.0+
  • Git (for plugin installation)

Quick Start

  1. Clone or navigate to this directory

  2. Copy environment file

    cp .env.example .env
  3. Build and start the stack

    docker compose up -d --build
  4. Wait for containers to boot: the first time it might take several minutes for the containers to boot. Check docker compose logs moodle for details. When the container is started you will se the message: Moodle container started...Starting Apache....

  5. Access Moodle

  6. Complete the Moodle installation wizard (if first time):

    • The first three steps steps (Choose a language, Confirm paths, Choose database driver) can be left with the default values
    • In the Database settings step, use the following values:
      • Database host: mysql
      • Database user: moodle
      • Database password: moodle
    • Finally, follow the instructions to complete the setup
    • Login with admin credentials from .env file

Pre-installed Plugins

The following plugins are pre-installed:

Activity Modules

  • mod_choicegroup - Choice group activity
  • mod_reservation - Reservation activity

Blocks

  • block_course_status - Course status block
  • block_qrcode - QR code block (v4.5-r1 for Moodle 4.5)
  • block_user_cohorts - User cohorts block (install manually; no public repo found)

Editor Plugins

  • atto_teamsmeeting - Teams meeting integration for Atto editor

Availability Conditions

  • availability_ipaddress - IP address availability condition

Reports

  • report_allbackups - All backups report

Themes

  • theme_academi - Academi theme
  • theme_boost_o365teams - Boost O365 Teams theme

Local Plugins

  • local_cohort_profile - Cohort profile
  • local_o365 - Office 365 integration
  • local_office365 - Office 365 local plugin
  • local_reminders - Reminders plugin

Installing Additional Plugins

Method 1: Using the plugins directory (Recommended)

  1. Download or clone the plugin

    # Example: Clone a plugin repository
    cd plugins
    git clone https://github.com/username/moodle-plugin_name.git plugin_name
  2. Place plugin in correct directory structure
    The plugin should be placed in plugins/ directory. The entrypoint script will automatically detect and install it based on the plugin type:

    • Activity modules: plugins/mod_pluginname/
    • Blocks: plugins/block_pluginname/
    • Local plugins: plugins/local_pluginname/
    • Themes: plugins/theme_pluginname/
    • etc.
  3. Restart the Moodle container

    docker compose restart moodle
  4. Install via Moodle admin

    • Go to Site administration → Plugins → Install plugins
    • Or use CLI: docker compose exec moodle php admin/cli/upgrade.php --non-interactive

Method 2: Direct installation in Moodle

  1. Access Moodle admin

    • Login as administrator
    • Navigate to Site administration → Plugins → Install plugins
  2. Upload plugin ZIP file

    • Upload the plugin ZIP file through the web interface
    • Moodle will automatically install it

Method 3: Manual installation

  1. Copy plugin to appropriate directory

    # Example for a block plugin
    cp -r plugin_directory moodle/blocks/pluginname
  2. Set permissions

    docker compose exec moodle chown -R www-data:www-data /var/www/html/blocks/pluginname
    docker compose exec moodle chmod -R 755 /var/www/html/blocks/pluginname
  3. Run Moodle upgrade

    docker compose exec moodle php admin/cli/upgrade.php --non-interactive

Directory Structure

moodle/
├── docker compose.yml          # Docker Compose configuration
├── Dockerfile                  # Custom Moodle image
├── docker-entrypoint.sh        # Container entrypoint script
├── install-plugins.sh          # Plugin installation script
├── .env                        # Environment variables (create from .env.example)
├── .env.example                # Example environment file
├── config.php.template         # Moodle config template
├── README.md                   # This file
├── moodle/                     # Moodle codebase (created on first run)
├── moodledata/                 # Moodle data directory (created on first run)
├── mysql-data/                 # MySQL data directory (created on first run)
└── plugins/                    # Custom plugins directory (optional)

Common Commands

Start services

docker compose up -d

Stop services

docker compose down

View logs

# All services
docker compose logs -f

# Moodle only
docker compose logs -f moodle

# MySQL only
docker compose logs -f mysql

Access Moodle container shell

docker compose exec moodle bash

Access MySQL

docker compose exec mysql mysql -u moodle -p moodle

Run Moodle CLI commands

# Upgrade database
docker compose exec moodle php admin/cli/upgrade.php --non-interactive

# Purge caches
docker compose exec moodle php admin/cli/purge_caches.php

# Create admin user
docker compose exec moodle php admin/cli/create_admin_user.php

Rebuild containers

docker compose build --no-cache

Configuration

Environment Variables

Edit .env file to customize:

  • MOODLE_URL - Moodle site URL
  • MOODLE_PORT - Port for Moodle web interface (default: 8080)
  • MOODLE_ADMIN_USER - Admin username
  • MOODLE_ADMIN_PASSWORD - Admin password
  • MYSQL_ROOT_PASSWORD - MySQL root password
  • MYSQL_DATABASE - Database name
  • MYSQL_USER - Database user
  • MYSQL_PASSWORD - Database password
  • MYSQL_PORT - MySQL port (default: 3306)

Updating Plugin URLs

If you need to update plugin repository URLs, edit install-plugins.sh and rebuild:

docker compose build --no-cache moodle
docker compose up -d

Troubleshooting

Port already in use

If port 8080 or 3306 is already in use (e.g. another MySQL instance), change them in .env:

MOODLE_PORT=8081
MYSQL_PORT=3307

Then run docker compose down and docker compose up -d again.

Data directory not writable ("parent folder not writable")

If the installer reports that the data folder cannot be created: use /var/moodledata as the data directory path. A symlink from /var/www/moodledata to /var/moodledata is created automatically, and /var/www is made writable at container start.

Permission issues

If you encounter permission issues with moodledata:

sudo chown -R $(id -u):$(id -g) moodledata/
chmod -R 777 moodledata/

Plugin installation fails

  1. Check plugin compatibility with Moodle 4.4
  2. Verify plugin repository URLs in install-plugins.sh
  3. Check container logs: docker compose logs moodle
  4. Try installing plugin manually via Moodle admin interface

Database connection errors

  1. Ensure MySQL container is healthy: docker compose ps
  2. Check MySQL logs: docker compose logs mysql
  3. Verify database credentials in .env match config.php

Reset everything

To start fresh:

docker compose down -v
rm -rf moodle/ moodledata/ mysql-data/
docker compose up -d --build

Development Tips

  • Hot-reload: Changes to Moodle code in moodle/ directory are immediately reflected
  • Plugin development: Place plugins in plugins/ directory for automatic installation
  • Database access: Use MySQL client or phpMyAdmin container for database management
  • Debug mode: PHP error reporting is enabled by default in this development setup

Security Notes

⚠️ This setup is for DEVELOPMENT ONLY

  • Default passwords are weak
  • Error reporting is enabled
  • Database is exposed on port 3306
  • Do NOT use this configuration in production

For production deployment:

  • Use strong passwords
  • Disable error reporting
  • Use Docker secrets or environment variable management
  • Restrict database access
  • Use SSL/TLS encryption
  • Follow Moodle security best practices

License

This Docker setup is provided as-is. Moodle and plugins have their own licenses.

Support

For issues with:

About

local moodle development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published