Initial commit of Moodle Cloud Foundry configuration

This commit is contained in:
Lukas Weberruß 2025-07-07 10:56:23 +02:00
commit 3cffd82d9b
10 changed files with 1720 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
moodle/

2
create-services.sh Normal file
View file

@ -0,0 +1,2 @@
cf create-service appcloud-mariadb1011 mariadb-1.4.10-single moodle-demo-mariadb
cf create-service autoscaler autoscaler-free-plan moodle-autoscaler

36
manifest.yaml Normal file
View file

@ -0,0 +1,36 @@
---
applications:
- name: moodle
memory: 4G
disk_quota: 2G
instances: 2
buildpack: php_buildpack
path: moodle
routes:
- route: moodle.cf.demo.stackit.rocks
- route: moodle.apps.01.cf.eu01.onstackit.cloud
env:
# -- Moodle-Datenbankkonfiguration --
# Ersetze die Service-Namen durch die Namen deiner Datenbank-Services
# CF_MYSQL_SERVICE_NAME: "moodle-demo-mariadb"
# -- Externe S3-Zugangsdaten --
S3_ACCESS_KEY: B0DNSBX7BOCK98QCFY3I
S3_SECRET_KEY: 6ZpD+grErQUtoer0us0fb9Ybqf0PWxXNOZcBI2G+
S3_BUCKET: moodle-demo
S3_ENDPOINT: https://object.storage.eu01.onstackit.cloud/
# -- PHP-Konfiguration für Moodle --
# Diese Konfiguration wird in eine .user.ini-Datei im Web-Root geschrieben
PHP_INI_SCAN_DIR: /home/vcap/app/php/etc/php.ini.d/
PHP_MEMORY_LIMIT: 1024
PHP_UPLOAD_MAX_FILESIZE: 100M
PHP_POST_MAX_SIZE: 100M
MAX_EXECUTION_TIME: 300
BP_PHP_LOG_LEVEL: WARNING
services:
- moodle-demo-mariadb
- moodle-autoscaler

BIN
moodle-5.0.1.tgz Normal file

Binary file not shown.

260
readme.md Normal file
View file

@ -0,0 +1,260 @@
-----
```markdown
# Moodle Deployment auf Cloud Foundry
Diese Anleitung beschreibt die Schritte für ein robustes und automatisch skalierendes Deployment der Lernplattform Moodle auf einer Cloud Foundry-Umgebung. Dies umfasst die Konfiguration für eine externe Datenbank, S3-Dateispeicher, Session-Handling für mehrere Instanzen und Autoskalierung.
## Voraussetzungen
* Zugang zu einer Cloud Foundry Umgebung.
* Das `cf` Command Line Interface (CLI) ist installiert.
* Zugangsdaten für einen S3-kompatiblen Object Storage sind vorhanden.
## Verzeichnisstruktur
Bevor du die Anwendung pushst, stelle sicher, dass deine lokale Verzeichnisstruktur wie folgt aussieht. Dies ist entscheidend für den Erfolg.
```
.
├── manifest.yml
└── moodle/
├── .bp-config/
│ ├── options.json
│ └── php/
│ └── php.ini.d/
│ ├── moodle.ini
│ └── mysqli.ini
├── httpd/
│ └── logs/
│ └── httpd.pid -\> /tmp/httpd.pid
├── lib/
├── logs/
│ ├── proc-man.log -\> /dev/stdout
│ └── rewrite.log -\> /dev/stdout
├── php/
│ └── var/
│ └── run/
│ └── php-fpm.pid -\> /tmp/php-fpm.pid
├── config.php
├── index.php
└── ... (alle anderen Moodle-Dateien und Ordner)
````
---
## Schritt-für-Schritt Anleitung
### 1. Moodle herunterladen
Erstelle ein Projektverzeichnis. Lade den Quellcode der Moodle-Version 5.0.1 mit `wget` herunter und entpacke ihn in einen Unterordner namens `moodle`.
```bash
wget [https://packaging.moodle.org/stable500/moodle-5.0.1.tgz](https://packaging.moodle.org/stable500/moodle-5.0.1.tgz)
tar -xzf moodle-5.0.1.tgz
````
### 2\. Cloud Foundry Services erstellen
Erstelle die benötigten Service-Instanzen in deiner Cloud Foundry-Umgebung.
```bash
# Datenbank-Service erstellen
cf create-service <dein-mariadb-service> <plan> moodle-demo-mariadb
# Autoscaler-Service erstellen
cf create-service autoscaler autoscaler-free-plan moodle-autoscaler
```
### 3\. Konfigurationsdateien anlegen und anpassen
Dies ist der wichtigste Schritt, bei dem alle spezifischen Konfigurationen für den Betrieb auf Cloud Foundry vorgenommen werden.
#### a) `manifest.yml` anlegen
Erstelle im Hauptverzeichnis deines Projekts die `manifest.yml`-Datei mit folgendem Inhalt. Passe die Routen sowie deine S3-Zugangsdaten an.
```yaml
---
applications:
- name: moodle
memory: 2G
disk_quota: 2G
buildpack: php_buildpack
path: moodle
routes:
- route: deine-moodle-route.deine-domain.de
env:
# Buildpack anweisen, weniger Debug-Logs in Dateien zu schreiben
BP_PHP_LOG_LEVEL: WARNING
# S3-Zugangsdaten für den Object Storage
S3_ACCESS_KEY: DEIN_S3_ACCESS_KEY
S3_SECRET_KEY: DEIN_S3_SECRET_KEY
S3_BUCKET: DEIN_S3_BUCKET_NAME
S3_ENDPOINT: DEIN_S3_ENDPOINT_URL
services:
- moodle-demo-mariadb
- moodle-autoscaler
# Konfiguration für den Autoscaler-Service
autoscaling:
min_instances: 2
max_instances: 4
rules:
- metric_type: cpu
threshold: 50
operator: ">"
adjustment: "+1"
breach_duration_secs: 60
cool_down_secs: 60
- metric_type: cpu
threshold: 10
operator: "<"
adjustment: "-1"
breach_duration_secs: 60
cool_down_secs: 60
```
#### b) Buildpack-Konfiguration (`.bp-config`)
Diese Dateien steuern das Verhalten des PHP Buildpacks.
1. **Web-Verzeichnis festlegen:**
```bash
echo '{"WEBDIR": "."}' > moodle/.bp-config/options.json
```
2. **PHP-Erweiterungen und -Einstellungen konfigurieren:**
```bash
mkdir -p moodle/.bp-config/php/php.ini.d/
echo "extension=mysqli" > moodle/.bp-config/php/php.ini.d/mysqli.ini
echo "max_input_vars = 5000" > moodle/.bp-config/php/php.ini.d/moodle.ini
```
#### c) Workarounds für das schreibgeschützte Dateisystem
Erstelle die Verzeichnisse und symbolischen Links für Log- und PID-Dateien.
```bash
# Für Log-Dateien (Umleitung auf die Standardausgabe)
mkdir -p moodle/logs
ln -s /dev/stdout moodle/logs/rewrite.log
ln -s /dev/stdout moodle/logs/proc-man.log
# Für Prozess-ID-Dateien (Umleitung in das beschreibbare /tmp-Verzeichnis)
mkdir -p moodle/httpd/logs
mkdir -p moodle/php/var/run
ln -s /tmp/httpd.pid moodle/httpd/logs/httpd.pid
ln -s /tmp/php-fpm.pid moodle/php/var/run/php-fpm.pid
```
#### d) `config.php` erstellen und anpassen
Kopiere `moodle/config-dist.php` zu `moodle/config.php` und ersetze den gesamten Inhalt mit der folgenden Vorlage. Passe `$CFG->wwwroot` an deine Route an.
```php
<?php // Moodle configuration file
unset($CFG);
global $CFG;
$CFG = new stdClass();
//=========================================================================
// 1. WEB SITE LOCATION
//=========================================================================
$CFG->wwwroot = '[https://deine-moodle-route.deine-domain.de](https://deine-moodle-route.deine-domain.de)';
//=========================================================================
// 2. DATABASE SETUP (wird automatisch aus VCAP_SERVICES gelesen)
//=========================================================================
$CFG->dbtype = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->prefix = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,
'dbport' => '',
'dbsocket' => '',
'dbcollation' => 'utf8mb4_unicode_ci',
);
// --- Lese Datenbank-Konfiguration aus VCAP_SERVICES (inkl. SSL) ---
$vcap_services_json = getenv('VCAP_SERVICES');
if ($vcap_services_json) {
$vcap_services = json_decode($vcap_services_json, true);
$db_service_key = null;
if (isset($vcap_services['appcloud-mariadb1011'])) { // Passe diesen Service-Namen ggf. an
$db_service_key = 'appcloud-mariadb1011';
}
if ($db_service_key && isset($vcap_services[$db_service_key][0]['credentials'])) {
$db_creds = $vcap_services[$db_service_key][0]['credentials'];
$CFG->dbhost = $db_creds['host'];
$CFG->dbname = $db_creds['name'];
$CFG->dbuser = $db_creds['username'];
$CFG->dbpass = $db_creds['password'];
if (isset($db_creds['cacrt']) && !empty($db_creds['cacrt'])) {
$ca_cert_path = '/tmp/db-ca.crt';
file_put_contents($ca_cert_path, $db_creds['cacrt']);
$CFG->dboptions['ssl_ca'] = $ca_cert_path;
$CFG->dboptions['ssl_verify_server_cert'] = true;
}
}
}
// --- Ende der VCAP_SERVICES-Datenbank-Konfiguration ---
//=========================================================================
// 3. DATAROOT (verweist auf das beschreibbare /tmp-Verzeichnis)
//=========================================================================
$CFG->dataroot = '/tmp/moodledata';
$CFG->directorypermissions = 0777;
//=========================================================================
// 4. S3 FILE STORAGE (wird automatisch aus Umgebungsvariablen gelesen)
//=========================================================================
if (getenv('S3_BUCKET')) {
$CFG->alternative_file_system_class = '\core_files\files\s3_file_system';
$CFG->s3_bucket = getenv('S3_BUCKET');
$CFG->s3_accesskey = getenv('S3_ACCESS_KEY');
$CFG->s3_secretkey = getenv('S3_SECRET_KEY');
$CFG->s3_endpoint = getenv('S3_ENDPOINT');
}
//=========================================================================
// 5. SESSION HANDLING (für mehrere Instanzen)
//=========================================================================
$CFG->session_handler_class = '\core\session\database';
//=========================================================================
// DO NOT ADD ANYTHING BELOW THIS LINE
//=========================================================================
require_once(__DIR__ . '/lib/setup.php');
```
### 4\. Anwendung deployen
Führe abschließend den Push-Befehl aus dem Hauptverzeichnis deines Projekts aus.
```bash
cf push
```
Nach Abschluss des Deployments ist deine Moodle-Instanz unter der konfigurierten Route erreichbar und wird gemäß deiner Policy automatisch skaliert.
```
```

4
s3.env Normal file
View file

@ -0,0 +1,4 @@
access_key=B0DNSBX7BOCK98QCFY3I
secret_key=6ZpD+grErQUtoer0us0fb9Ybqf0PWxXNOZcBI2G+
bucket=moodle-demo
endpoint=https://object.storage.eu01.onstackit.cloud/

View file

@ -0,0 +1,3 @@
{
"WEBDIR": "."
}

View file

@ -0,0 +1 @@
max_input_vars = 5000

View file

@ -0,0 +1 @@
extension=mysqli

1412
template/config.php Normal file

File diff suppressed because it is too large Load diff