Skip to main content

Overview

The ipMoodle Dockerfile is built on php:8.2-fpm-alpine and includes essential PHP extensions for Moodle. You can extend this base image to add custom PHP extensions required for specific Moodle plugins or integrations.

Understanding the Extension Installation Pattern

The Dockerfile (source/Dockerfile:1-39) follows a three-step pattern for installing PHP extensions:
1

Install system dependencies

Add required development libraries using apk add --no-cache
2

Configure extensions (if needed)

Some extensions like GD require configuration before compilation
3

Install PHP extensions

Use docker-php-ext-install to compile and enable extensions

Currently Installed Extensions

The base ipMoodle image includes these extensions:
  • intl - Internationalization support
  • soap - SOAP protocol support
  • zip - ZIP archive handling
  • pgsql - PostgreSQL database driver
  • pdo_pgsql - PDO driver for PostgreSQL
  • exif - Image metadata reading
  • opcache - PHP opcode caching
  • bcmath - Arbitrary precision mathematics
  • sockets - Socket communication
  • mbstring - Multibyte string handling
  • sodium - Modern cryptography
  • gd - Image processing (with FreeType and JPEG support)

Adding a Simple PHP Extension

For extensions that don’t require external dependencies:
1

Edit the Dockerfile

Open source/Dockerfile and locate the extension installation block (line 26-27):
RUN docker-php-ext-install -j$(nproc) \
    intl soap zip pgsql pdo_pgsql exif opcache bcmath sockets mbstring sodium
2

Add your extension

Append your extension name to the list:
RUN docker-php-ext-install -j$(nproc) \
    intl soap zip pgsql pdo_pgsql exif opcache bcmath sockets mbstring sodium pcntl
3

Rebuild the container

docker-compose down
docker-compose build --no-cache app
docker-compose up -d
The -j$(nproc) flag enables parallel compilation using all available CPU cores, speeding up the build process.

Adding Extensions with Dependencies

Extensions requiring system libraries need a two-step process:

Example: Adding LDAP Extension

1

Add system dependencies

Edit the dependency installation block (line 4-19):
RUN apk add --no-cache \
    git \
    linux-headers \
    oniguruma-dev \
    libsodium-dev \
    icu-dev \
    libpng-dev \
    libjpeg-turbo-dev \
    freetype-dev \
    libzip-dev \
    libxml2-dev \
    postgresql-dev \
    zlib-dev \
    shadow \
    ghostscript \
    dcron \
    openldap-dev  # Add this line
2

Add the PHP extension

RUN docker-php-ext-install -j$(nproc) \
    intl soap zip pgsql pdo_pgsql exif opcache bcmath sockets mbstring sodium ldap
3

Rebuild and verify

docker-compose build --no-cache app
docker-compose up -d
docker exec moodle_app php -m | grep ldap

Adding Extensions Requiring Configuration

Some extensions need configuration before installation, similar to GD (line 22-23):

Example: Adding IMAP Extension

# Install dependencies
RUN apk add --no-cache \
    imap-dev \
    openssl-dev \
    krb5-dev

# Configure and install
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
    && docker-php-ext-install -j$(nproc) imap

Installing PECL Extensions

For extensions not bundled with PHP, use PECL:

Example: Adding Redis Extension

1

Install build dependencies

RUN apk add --no-cache --virtual .build-deps \
    $PHPIZE_DEPS \
    autoconf \
    g++ \
    make
2

Install the PECL extension

RUN pecl install redis \
    && docker-php-ext-enable redis
3

Clean up build dependencies

RUN apk del .build-deps
RUN apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        autoconf \
        g++ \
        make \
    && pecl install redis \
    && docker-php-ext-enable redis \
    && apk del .build-deps

Verifying Installed Extensions

After rebuilding, verify your extensions are loaded:
# List all enabled extensions
docker exec moodle_app php -m

# Check specific extension
docker exec moodle_app php -m | grep redis

# View extension configuration
docker exec moodle_app php -i | grep -A 5 "redis"

Configuring Extension Settings

Add extension-specific settings to the PHP configuration (line 30-36):
RUN { \
    echo 'max_input_vars=5000'; \
    echo 'memory_limit=512M'; \
    echo 'upload_max_filesize=512M'; \
    echo 'post_max_size=512M'; \
    echo 'max_execution_time=600'; \
    echo 'opcache.enable=1'; \
    echo 'opcache.memory_consumption=128'; \
    echo 'redis.session.locking_enabled=1'; \
} > /usr/local/etc/php/conf.d/moodle.ini
Always rebuild with --no-cache flag when modifying the Dockerfile to ensure changes are applied:
docker-compose build --no-cache app

Common Moodle Extensions

Depending on your Moodle plugins, you may need:
ExtensionUse CaseDependencies
ldapLDAP authenticationopenldap-dev
imapEmail integrationimap-dev openssl-dev krb5-dev
redisSession/cache storagePECL extension
imagickAdvanced image processingimagemagick-dev
xslXML transformationslibxslt-dev
curlHTTP requestsUsually included
ftpFTP repository supportNone

Troubleshooting

Extension fails to compile

Ensure all required -dev packages are installed in the Alpine dependency block. Search for the extension name + “alpine linux” to find required packages.
Always use --no-cache when testing new extensions:
docker-compose build --no-cache app
Check the PHP error log:
docker logs moodle_app

Extension loads but Moodle doesn’t recognize it

  1. Verify the extension is enabled:
    docker exec moodle_app php -m | grep your_extension
    
  2. Restart the PHP-FPM service:
    docker-compose restart app
    
  3. Clear Moodle caches from Site administration > Development > Purge all caches
Some Moodle plugins check for specific PHP extensions during installation. Always verify extension requirements before installing plugins.

Build docs developers (and LLMs) love