Moodle

Moodle

Moodle is a learning platform designed to provide educators, administrators and learners with a single robust, secure and integrated system to create personalised learning environments.

This doc explains how to configure Moodle from source. Alternatively, an already configured repository exists as well on Clever Cloud’s GitHub page.

How to Configure and Deploy Moodle on Clever Cloud

Download Moodle

You can download Moodle from https://download.moodle.org and initialize a Git repository at root with git init.

Configure config.php

Duplicate config-dist.php and rename it config.php. Update the following variables as follows:

config.php
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
?php  // Moodle configuration file

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

$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = getenv("MYSQL_ADDON_HOST");
$CFG->dbname    = getenv("MYSQL_ADDON_DB");
$CFG->dbuser    = getenv("MYSQL_ADDON_USER");
$CFG->dbpass    = getenv("MYSQL_ADDON_PASSWORD");
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbport' => getenv("MYSQL_ADDON_PORT"),
  'dbsocket' => '',
  'dbcollation' => 'utf8mb4_0900_ai_ci',
);

$CFG->wwwroot   = getenv("URL");
$CFG->dataroot  = getenv("APP_HOME") . '/moodledata';
$CFG->admin     = getenv("ADMIN");

$CFG->directorypermissions = 0777;

$CFG->sslproxy = true;

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

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

Commit changes.

Declare the PHP Application

On Clever Cloud Console, click Create > An application and choose a PHP application with Git deployment. Add a MySQL add-on during the process.

Set Up Environment Variables

Add the following environment variables to tour PHP application:

CC_PHP_VERSION="8"
MAX_INPUT_VARS="5000"
URL="<your-url"

If you don’t have an domain for your Moodle application yet, you’ll be able to add a test domain provided by Clever Cloud in step 6.

Set Up moodledata Folder

In this step you enable storage outside of your application, which Moodle requires to run. Use a File System Bucket to store all uploaded files and appearance set ups away from the application server, as recommended by Moodle.

Create an FS Bucket add-on and link it to your PHP application. In your FS Bucket dashboard, find the path variable. It should look like this: CC_FS_BUCKET=/some/empty/folder:bucket-<bucket_id>.

Add this variable to your PHP application and replace /some/empty/folder by /moodledata. Don’t forget to update changes.

Set Up Domain

Moodle needs an URL declared in variables to work properly. You can set it up in Domains names, from your PHP application menu. If you don’t have a domain name yet, you can use a cleverapp.io subdomain provided by Clever Cloud for test purposes.

Don’t forget to update URL="<your-url" if you haven’t yet.

Deploy

Get the remote in your application menu > Information > Deployment URL and add it to Git with git remote add clever <clever-remote-url>. Then, push your code with git push clever -u master

💡 If you get a reference error when pushing, try this: git push clever main:master.

Cron for Moodle

Moodle recommends to set up a Cron job that runs every minute. For the Cron to execute as a PHP file, you will need to add a shebang at the very top of admin/cli/cron.php, like this: #!/usr/bin/env php.

Declare the cron in Clever Cloud

Create a clevercloud/cron.json file with a string to run admin/cli/cron.phpevery minute:

clevercloud/cron.json
[
  "* * * * * $ROOT/admin/cli/cron.php"
]

You might encounter errors when the Cron tries to access moodledata in your FS Bucket. For FS Bucket backups, look for a dedicated tool like rclone.

Note: this repository is already configured to run /admin/cli/cron.php every minute as a cron job.

🎓 Further Help

See Moodle installation documentation for further help and development configuration.

Last updated on

Did this documentation help you ?