-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.php
142 lines (127 loc) · 3.85 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/*
* Moodle configuration file
*/
unset($CFG);
global $CFG;
$CFG = new stdClass();
/*
* Database configuration
*/
$CFG->dbtype = getenv('DB_TYPE') ?: 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost = getenv('DB_HOST') ?: '127.0.0.1';
$CFG->dbname = getenv('DB_DATABASE') ?: 'moodle';
$CFG->dbuser = getenv('DB_USERNAME') ?: 'moodle';
$CFG->dbpass = getenv('DB_PASSWORD') ?: '';
$CFG->prefix = 'mdl_';
$CFG->dboptions = [
'dbpersist' => 0,
'dbport' => intval(getenv('DB_PORT') ?: 3306),
'dbsocket' => getenv('DB_SOCKET') ?: '',
'dbcollation' => 'utf8mb4_unicode_ci',
];
/*
* Redis cache / session store configuration
*/
$redisHost = getenv('REDIS_HOST') ?: '127.0.0.1';
$redisPort = intval(getenv('REDIS_PORT') ?: 6379);
$redisPassword = getenv('REDIS_PASSWORD') ?: '';
$CFG->alternative_cache_factory_class = 'tool_forcedcache_cache_factory';
$CFG->tool_forcedcache_config_array = [
'stores' => [
'apcu' => [
'type' => 'apcu',
'config' => [
'prefix' => 'apcu_',
],
],
'redis' => [
'type' => 'redis',
'config' => [
'server' => sprintf('%s:%s', $redisHost, $redisPort),
'password' => $redisPassword,
'prefix' => 'mdl_cache_',
'serializer' => 1, // \Redis::SERIALIZER_PHP
'compressor' => 0, // \cachestore_redis::COMPRESSOR_NONE
],
],
'local_file' => [
'type' => 'file',
'config' => [
'path' => '/tmp/local-cache-file',
'autocreate' => 1,
],
],
],
'rules' => [
'application' => [
// These get queried on almost every page
// and don't need to be shared between instances,
// so let's stick them on APCu for speeeeeeeed
[
'conditions' => [
'name' => 'core/langmenu',
],
'stores' => ['apcu', 'redis'],
],
[
'conditions' => [
'name' => 'core/plugin_functions',
],
'stores' => ['apcu', 'redis'],
],
[
'conditions' => [
'name' => 'core/string',
],
'stores' => ['apcu', 'redis'],
],
// HTMLPurifier spits out some big files,
// so let's store it locally in tmpfs
[
'conditions' => [
'name' => 'core/htmlpurifier',
],
'stores' => ['local_file'],
],
// Other things that work locally can go to tmpfs
[
'conditions' => [
'canuselocalstore' => true,
],
'stores' => ['local_file', 'redis'],
],
// Everything else to Redis!
['stores' => ['redis']],
],
'session' => [
['stores' => ['redis']],
],
'request' => [],
],
];
$CFG->session_handler_class = '\core\session\redis';
$CFG->session_redis_host = $redisHost;
$CFG->session_redis_port = $redisPort;
$CFG->session_redis_database = 0;
$CFG->session_redis_auth = $redisPassword;
$CFG->session_redis_prefix = 'mdl_session_';
/*
* URL and filesystem configuration
*/
$CFG->wwwroot = getenv('WWW_ROOT') ?: 'http://localhost';
$CFG->sslproxy = getenv('SSL_PROXY') !== false;
$CFG->dataroot = getenv('DATA_ROOT') ?: '';
$CFG->directorypermissions = 0777;
/*
* Administration configuration
*/
$CFG->alternative_component_cache = __DIR__ . '/core_component.php';
$CFG->upgradekey = getenv('UPGRADE_KEY') ?: null;
$CFG->disableupdateautodeploy = true;
$CFG->preventexecpath = true;
/*
* Pass it off to Moodle core
*/
require_once __DIR__ . '/lib/setup.php';