Skip to content

Commit c719094

Browse files
authored
Merge pull request #2083 from Websoft9/feat/moodle-update-20260319
feat: update moodle app configuration
2 parents 1c8daf3 + d7f028f commit c719094

18 files changed

Lines changed: 180 additions & 1019 deletions

apps/moodle/.env

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
W9_POWER_PASSWORD='mCjG5CnUKA!GsOXK'
2-
W9_VERSION='5.1.1'
2+
W9_VERSION='5.1.3'
33
W9_DIST='community'
44
W9_REPO=websoft9dev/moodle
55

66
#### -- Not allowed to edit below environments when recreate app based on existing data -- ####
77
W9_ID='moodle'
88
W9_HTTP_PORT=80
9-
W9_HTTP_PORT_SET='9001'
10-
W9_URL='appname.example.com'
9+
W9_HTTP_PORT_SET=9001
10+
W9_URL=internet_ip:$W9_HTTP_PORT_SET
1111
W9_URL_REPLACE=true
12+
W9_ADMIN_PATH=/admin
13+
W9_LOGIN_USER=admin
14+
W9_LOGIN_PASSWORD=$W9_POWER_PASSWORD
1215
W9_DB_EXPOSE="mariadb"
13-
W9_MARIADB_VERSION="11.4"
14-
W9_DIST='community'
16+
W9_DB_VERSION="11.4"
1517
W9_NETWORK=websoft9
1618
#### --------------------------------------------------------------------------------------- ####
19+
20+
MOODLE_URL=http://$W9_URL
21+
MOODLE_DB_HOST=$W9_ID-mariadb
22+
MOODLE_DB_NAME=moodle
23+
MOODLE_DB_USER=moodle
24+
MOODLE_DB_TYPE=mariadb
25+
MOODLE_DB_PORT=3306
26+
MOODLE_ADMIN_USER=$W9_LOGIN_USER
27+
MOODLE_ADMIN_PASSWORD=$W9_POWER_PASSWORD
28+
MOODLE_DB_PASSWORD=$W9_POWER_PASSWORD
29+
MOODLE_ADMIN_EMAIL=admin@example.com
30+
MOODLE_SITE_NAME=Moodle Learning Platform
31+
MYSQL_ROOT_PASSWORD=$W9_POWER_PASSWORD
32+
MYSQL_DATABASE=moodle
33+
MYSQL_USER=moodle
34+
MYSQL_PASSWORD=$W9_POWER_PASSWORD

apps/moodle/Dockerfile

Lines changed: 32 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,51 @@
1-
# Moodle Dockerfile based on official php:apache
2-
# Reference: https://docs.moodle.org/501/en/Installation_quick_guide
1+
# Moodle Dockerfile based on moodlehq/moodle-php-apache
2+
# Official base image: https://hub.docker.com/r/moodlehq/moodle-php-apache
3+
# Install guide: https://docs.moodle.org/en/Installation_quick_guide
34

4-
FROM php:8.2-apache
5+
FROM moodlehq/moodle-php-apache:8.3-bullseye
56

67
LABEL org.opencontainers.image.authors="https://www.websoft9.com" \
7-
org.opencontainers.image.description="Moodle packaged by Websoft9" \
8-
org.opencontainers.image.source="https://packaging.moodle.org/stable501/moodle-5.1.1.zip" \
9-
org.opencontainers.image.title="Moodle" \
10-
org.opencontainers.image.vendor="Websoft9 Inc." \
11-
org.opencontainers.image.version="5.1.1"
12-
13-
# Moodle version
14-
ENV MOODLE_VERSION=5.1.1 \
15-
MOODLE_DATA=/var/moodledata
16-
17-
# Install system dependencies and PHP extensions required by Moodle
18-
RUN apt-get update && apt-get install -y \
19-
# Basic tools
20-
wget \
8+
org.opencontainers.image.description="Moodle packaged by Websoft9" \
9+
org.opencontainers.image.title="Moodle" \
10+
org.opencontainers.image.vendor="Websoft9 Inc." \
11+
org.opencontainers.image.version="5.1.3"
12+
13+
ENV MOODLE_VERSION=5.1.3 \
14+
MOODLE_DATA=/var/moodledata \
15+
APACHE_DOCUMENT_ROOT=/var/www/html/public
16+
17+
# Install system tools (all Moodle PHP extensions are pre-installed by base image)
18+
RUN apt-get update && apt-get install -y --no-install-recommends \
19+
curl \
2120
unzip \
22-
git \
2321
cron \
24-
# Libraries for PHP extensions
25-
libicu-dev \
26-
libpng-dev \
27-
libjpeg62-turbo-dev \
28-
libfreetype6-dev \
29-
libxml2-dev \
30-
libzip-dev \
31-
libldap2-dev \
32-
libpq-dev \
33-
libonig-dev \
34-
libxslt1-dev \
35-
libcurl4-openssl-dev \
36-
# Database clients
3722
default-mysql-client \
38-
postgresql-client \
39-
# Cleanup
4023
&& rm -rf /var/lib/apt/lists/*
4124

42-
# Configure and install PHP extensions required by Moodle
43-
# GD extension
44-
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
45-
&& docker-php-ext-install -j$(nproc) gd
46-
47-
# Install other extensions
48-
RUN docker-php-ext-install -j$(nproc) \
49-
intl \
50-
mysqli \
51-
pgsql \
52-
pdo_mysql \
53-
pdo_pgsql \
54-
opcache \
55-
zip \
56-
soap \
57-
mbstring \
58-
exif
59-
60-
# LDAP extension (configure separately to avoid path issues)
61-
RUN docker-php-ext-configure ldap \
62-
&& docker-php-ext-install ldap
63-
64-
# Install additional recommended PHP extensions
65-
RUN pecl install redis \
66-
&& docker-php-ext-enable redis
67-
68-
# Configure PHP settings for Moodle
69-
RUN { \
70-
echo 'file_uploads = On'; \
71-
echo 'memory_limit = 512M'; \
72-
echo 'upload_max_filesize = 512M'; \
73-
echo 'post_max_size = 512M'; \
74-
echo 'max_execution_time = 600'; \
75-
echo 'max_input_vars = 5000'; \
76-
echo 'max_input_time = 600'; \
77-
echo 'session.save_handler = files'; \
78-
echo 'session.auto_start = 0'; \
79-
echo 'session.gc_maxlifetime = 1440'; \
80-
echo 'zend.exception_ignore_args = On'; \
81-
} > /usr/local/etc/php/conf.d/moodle.ini
82-
83-
# Configure OPcache for performance
84-
RUN { \
85-
echo 'opcache.enable = 1'; \
86-
echo 'opcache.memory_consumption = 128'; \
87-
echo 'opcache.interned_strings_buffer = 8'; \
88-
echo 'opcache.max_accelerated_files = 4000'; \
89-
echo 'opcache.revalidate_freq = 60'; \
90-
echo 'opcache.fast_shutdown = 1'; \
91-
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
92-
9325
# Enable Apache modules
94-
RUN a2enmod rewrite expires headers ssl
95-
96-
# Configure Apache DocumentRoot to use /public directory (Moodle 5.0+ requirement)
97-
RUN sed -i 's|DocumentRoot /var/www/html|DocumentRoot /var/www/html/public|g' /etc/apache2/sites-available/000-default.conf \
98-
&& sed -i 's|<Directory /var/www/>|<Directory /var/www/html/>\n Options Indexes FollowSymLinks\n AllowOverride All\n Require all granted\n</Directory>\n<Directory /var/www/html/public/>|g' /etc/apache2/apache2.conf
26+
RUN a2enmod rewrite expires headers
9927

100-
# Create moodledata directory with proper permissions
28+
# Create Moodle data directory with correct permissions
10129
RUN mkdir -p ${MOODLE_DATA} \
10230
&& chown -R www-data:www-data ${MOODLE_DATA} \
103-
&& chmod -R 0777 ${MOODLE_DATA}
31+
&& chmod 777 ${MOODLE_DATA}
10432

105-
# Download and extract Moodle
33+
# Download Moodle source code
34+
# For CI/CD: no proxy needed. For local builds behind a firewall:
35+
# docker build --network=host --build-arg CURL_PROXY=socks5h://127.0.0.1:1080 ...
36+
ARG CURL_PROXY=
10637
WORKDIR /var/www/html
107-
RUN wget -O moodle.zip "https://packaging.moodle.org/stable501/moodle-${MOODLE_VERSION}.zip" \
108-
&& unzip -q moodle.zip \
109-
&& mv moodle/* moodle/.??* . 2>/dev/null || true \
110-
&& rmdir moodle \
111-
&& rm moodle.zip \
112-
&& chown -R www-data:www-data /var/www/html \
113-
&& chmod -R 0755 /var/www/html
38+
RUN curl ${CURL_PROXY:+--proxy "$CURL_PROXY"} -fsSL -o /tmp/moodle.zip \
39+
"https://packaging.moodle.org/stable501/moodle-${MOODLE_VERSION}.zip" \
40+
&& unzip -q /tmp/moodle.zip -d /tmp/moodle_src \
41+
&& cp -a /tmp/moodle_src/moodle/. /var/www/html/ \
42+
&& rm -rf /tmp/moodle.zip /tmp/moodle_src \
43+
&& chown -R www-data:www-data /var/www/html
11444

115-
# Setup cron job for Moodle
116-
RUN echo "* * * * * www-data /usr/local/bin/php /var/www/html/admin/cli/cron.php >/dev/null" >> /etc/crontab
45+
# Moodle scheduled task (cron)
46+
RUN echo "* * * * * www-data /usr/local/bin/php /var/www/html/admin/cli/cron.php >/dev/null 2>&1" \
47+
>> /etc/crontab
11748

118-
# Create entrypoint script
11949
COPY docker-entrypoint.sh /usr/local/bin/
12050
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
12151

apps/moodle/Notes.md

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +0,0 @@
1-
## About
2-
3-
Moodle Docker deployment with MariaDB support.
4-
5-
## URL Configuration
6-
7-
### Changing from IP to Domain
8-
9-
When you need to change from IP access to domain access, you need to update both the config file and database:
10-
11-
1. **Update config.php** (in container `/var/www/html/config.php`):
12-
```bash
13-
docker exec -it moodle sed -i "s|http://.*';|http://your-domain.com';|g" /var/www/html/config.php
14-
```
15-
16-
2. **Update database**:
17-
```bash
18-
docker exec -it moodle-mariadb mariadb -umoodle -p moodle -e "UPDATE mdl_config SET value = 'http://your-domain.com' WHERE name = 'wwwroot';"
19-
```
20-
21-
3. **Clear Moodle cache**:
22-
```bash
23-
docker exec -it moodle php /var/www/html/admin/cli/purge_caches.php
24-
```
25-
26-
### HTTPS Configuration with Reverse Proxy
27-
28-
If you encounter **infinite redirect loop** after configuring HTTPS certificate (via Nginx Proxy Manager), you need to configure Moodle to work behind a reverse proxy.
29-
30-
**Problem**:
31-
- config.php has `$CFG->wwwroot = 'http://domain.com';`
32-
- User accesses via HTTPS
33-
- Moodle detects protocol mismatch and redirects infinitely
34-
35-
**Solution**: Add reverse proxy configuration to `/var/www/html/config.php`:
36-
37-
```bash
38-
# Enter the container
39-
docker exec -it moodle bash
40-
41-
# Edit config.php and add these lines BEFORE require_once():
42-
vi /var/www/html/config.php
43-
```
44-
45-
Add the following configuration **BEFORE** the `require_once(__DIR__ . '/lib/setup.php');` line:
46-
47-
```php
48-
// HTTPS Reverse Proxy Configuration
49-
$CFG->wwwroot = 'https://safeline.websoft9.cn'; // Change to HTTPS
50-
51-
// Force HTTPS when behind reverse proxy
52-
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
53-
$_SERVER['HTTPS'] = 'on';
54-
$_SERVER['SERVER_PORT'] = 443;
55-
}
56-
57-
// Alternative: Force HTTPS for all requests
58-
// $CFG->reverseproxy = true;
59-
// $_SERVER['HTTPS'] = 'on';
60-
```
61-
62-
**Complete config.php example**:
63-
64-
```php
65-
<?php // Moodle configuration file
66-
67-
unset($CFG);
68-
global $CFG;
69-
$CFG = new stdClass();
70-
71-
$CFG->dbtype = 'mariadb';
72-
$CFG->dblibrary = 'native';
73-
$CFG->dbhost = 'moodle_edf5j-mariadb';
74-
$CFG->dbname = 'moodle';
75-
$CFG->dbuser = 'moodle';
76-
$CFG->dbpass = 'qB!5Glu37szh1bUd';
77-
$CFG->prefix = 'mdl_';
78-
$CFG->dboptions = array(
79-
'dbpersist' => 0,
80-
'dbport' => '3306',
81-
'dbsocket' => '',
82-
'dbcollation' => 'utf8mb4_unicode_ci',
83-
);
84-
85-
// IMPORTANT: Change to HTTPS
86-
$CFG->wwwroot = 'https://safeline.websoft9.cn';
87-
$CFG->dataroot = '/var/moodledata';
88-
$CFG->admin = 'admin';
89-
90-
$CFG->directorypermissions = 0777;
91-
92-
// HTTPS Reverse Proxy Support
93-
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
94-
$_SERVER['HTTPS'] = 'on';
95-
$_SERVER['SERVER_PORT'] = 443;
96-
}
97-
98-
require_once(__DIR__ . '/lib/setup.php');
99-
100-
// There is no php closing tag in this file,
101-
// it is intentional because it prevents trailing whitespace problems!
102-
```
103-
104-
**Quick Fix Command**:
105-
106-
```bash
107-
# Method 1: Edit manually
108-
docker exec -it moodle vi /var/www/html/config.php
109-
110-
# Method 2: Use sed to update URL to HTTPS
111-
docker exec -it moodle sed -i "s|http://safeline.websoft9.cn|https://safeline.websoft9.cn|g" /var/www/html/config.php
112-
113-
# Then add reverse proxy config (manual edit required)
114-
docker exec -it moodle vi /var/www/html/config.php
115-
# Add the HTTP_X_FORWARDED_PROTO check before require_once()
116-
```
117-
118-
**Update database** (also change to HTTPS):
119-
120-
```bash
121-
docker exec -it moodle_edf5j-mariadb mariadb -umoodle -pqB\!5Glu37szh1bUd moodle -e "UPDATE mdl_config SET value = 'https://safeline.websoft9.cn' WHERE name = 'wwwroot';"
122-
```
123-
124-
**Clear cache**:
125-
126-
```bash
127-
docker exec -it moodle php /var/www/html/admin/cli/purge_caches.php
128-
```
129-
130-
### Verify Nginx Proxy Manager Configuration
131-
132-
Ensure your Nginx Proxy Manager has these settings:
133-
134-
1. **SSL Certificate**: Valid and properly configured
135-
2. **Force SSL**: Enabled
136-
3. **Custom Nginx Configuration** (Advanced tab):
137-
138-
```nginx
139-
# Ensure these headers are passed to backend
140-
proxy_set_header X-Forwarded-Proto $scheme;
141-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
142-
proxy_set_header X-Real-IP $remote_addr;
143-
proxy_set_header Host $host;
144-
```
145-
146-
## Troubleshooting
147-
148-
### Issue: Infinite Redirect Loop
149-
- **Cause**: Protocol mismatch between config.php (http) and actual access (https)
150-
- **Solution**: Change `$CFG->wwwroot` to HTTPS and add reverse proxy support
151-
152-
### Issue: "Site not secure" warning
153-
- **Cause**: Mixed content (HTTP resources on HTTPS page)
154-
- **Solution**: Ensure `$CFG->wwwroot` uses HTTPS
155-
156-
### Issue: Session errors
157-
- **Cause**: Cookie domain mismatch
158-
- **Solution**: Clear browser cookies and cache after changing URL

apps/moodle/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
This is an **[Docker Compose template](https://github.com/Websoft9/docker-library)** powered by [Websoft9](https://www.websoft9.com) based on Docker for Moodle:
44

55

6-
- community: 5.0, latest
6+
- community: 5.1.3, latest
77

88

99
## System Requirements
1010

11-
The following are the minimal [recommended requirements](https://github.com/moodle/docker#recommended-system-requirements):
11+
The following are the minimal [recommended requirements](https://docs.moodle.org/en/Installing_Moodle#System_requirements):
1212

1313
* **RAM**: 1 GB or more
1414
* **CPU**: 1 cores or higher

0 commit comments

Comments
 (0)