]> BookStack Code Mirror - bookstack/blob - app/Config/database.php
do some cleanup and add doc
[bookstack] / app / Config / database.php
1 <?php
2
3 /**
4  * Database configuration options.
5  *
6  * Changes to these config files are not supported by BookStack and may break upon updates.
7  * Configuration should be altered via the `.env` file or environment variables.
8  * Do not edit this file unless you're happy to maintain any changes yourself.
9  */
10
11 // REDIS
12 // Split out configuration into an array
13 if (env('REDIS_SERVERS', false)) {
14     $redisDefaults = ['host' => '127.0.0.1', 'port' => '6379', 'database' => '0', 'password' => null];
15     $redisServers = explode(',', trim(env('REDIS_SERVERS', '127.0.0.1:6379:0'), ','));
16     $redisConfig = ['client' => 'predis'];
17     $cluster = count($redisServers) > 1;
18
19     if ($cluster) {
20         $redisConfig['clusters'] = ['default' => []];
21     }
22
23     foreach ($redisServers as $index => $redisServer) {
24         $redisServerDetails = explode(':', $redisServer);
25
26         $serverConfig = [];
27         $configIndex = 0;
28         foreach ($redisDefaults as $configKey => $configDefault) {
29             $serverConfig[$configKey] = ($redisServerDetails[$configIndex] ?? $configDefault);
30             $configIndex++;
31         }
32
33         if ($cluster) {
34             $redisConfig['clusters']['default'][] = $serverConfig;
35         } else {
36             $redisConfig['default'] = $serverConfig;
37         }
38     }
39 }
40
41 // MYSQL
42 // Split out port from host if set
43 $mysql_host = env('DB_HOST', 'localhost');
44 $mysql_host_exploded = explode(':', $mysql_host);
45 $mysql_port = env('DB_PORT', 3306);
46 if (count($mysql_host_exploded) > 1) {
47     $mysql_host = $mysql_host_exploded[0];
48     $mysql_port = intval($mysql_host_exploded[1]);
49 }
50
51 return [
52
53     // Default database connection name.
54     // Options: mysql, mysql_testing
55     'default' => env('DB_CONNECTION', 'mysql'),
56
57     // Available database connections
58     // Many of those shown here are unsupported by BookStack.
59     'connections' => [
60
61         'mysql' => [
62             'driver'         => 'mysql',
63             'url'            => env('DATABASE_URL'),
64             'host'           => $mysql_host,
65             'database'       => env('DB_DATABASE', 'forge'),
66             'username'       => env('DB_USERNAME', 'forge'),
67             'password'       => env('DB_PASSWORD', ''),
68             'unix_socket'    => env('DB_SOCKET', ''),
69             'port'           => $mysql_port,
70             'charset'        => 'utf8mb4',
71             'collation'      => 'utf8mb4_unicode_ci',
72             // Prefixes are only semi-supported and may be unstable
73             // since they are not tested as part of our automated test suite.
74             // If used, the prefix should not be changed otherwise you will likely receive errors.
75             'prefix'         => env('DB_TABLE_PREFIX', ''),
76             'prefix_indexes' => true,
77             'strict'         => false,
78             'engine'         => null,
79             'options'        => extension_loaded('pdo_mysql') ? array_filter([
80                 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
81             ]) : [],
82         ],
83
84         'mysql_testing' => [
85             'driver'         => 'mysql',
86             'url'            => env('TEST_DATABASE_URL'),
87             'host'           => '127.0.0.1',
88             'database'       => 'bookstack-test',
89             'username'       => env('MYSQL_USER', 'bookstack-test'),
90             'password'       => env('MYSQL_PASSWORD', 'bookstack-test'),
91             'port'           => $mysql_port,
92             'charset'        => 'utf8mb4',
93             'collation'      => 'utf8mb4_unicode_ci',
94             'prefix'         => '',
95             'prefix_indexes' => true,
96             'strict'         => false,
97         ],
98
99     ],
100
101     // Migration Repository Table
102     // This table keeps track of all the migrations that have already run for
103     // your application. Using this information, we can determine which of
104     // the migrations on disk haven't actually been run in the database.
105     'migrations' => 'migrations',
106
107     // Redis configuration to use if set
108     'redis' => $redisConfig ?? [],
109
110 ];
Morty Proxy This is a proxified and sanitized view of the page, visit original site.