]> BookStack Code Mirror - bookstack/blob - app/Config/database.php
Drawings: Added class to extract drawio data from png files
[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 $mysqlHost = env('DB_HOST', 'localhost');
44 $mysqlHostExploded = explode(':', $mysqlHost);
45 $mysqlPort = env('DB_PORT', 3306);
46 $mysqlHostIpv6 = str_starts_with($mysqlHost, '[');
47 if ($mysqlHostIpv6 && str_contains($mysqlHost, ']:')) {
48     $mysqlHost = implode(':', array_slice($mysqlHostExploded, 0, -1));
49     $mysqlPort = intval(end($mysqlHostExploded));
50 } else if (!$mysqlHostIpv6 && count($mysqlHostExploded) > 1) {
51     $mysqlHost = $mysqlHostExploded[0];
52     $mysqlPort = intval($mysqlHostExploded[1]);
53 }
54
55 return [
56
57     // Default database connection name.
58     // Options: mysql, mysql_testing
59     'default' => env('DB_CONNECTION', 'mysql'),
60
61     // Available database connections
62     // Many of those shown here are unsupported by BookStack.
63     'connections' => [
64
65         'mysql' => [
66             'driver'         => 'mysql',
67             'url'            => env('DATABASE_URL'),
68             'host'           => $mysqlHost,
69             'database'       => env('DB_DATABASE', 'forge'),
70             'username'       => env('DB_USERNAME', 'forge'),
71             'password'       => env('DB_PASSWORD', ''),
72             'unix_socket'    => env('DB_SOCKET', ''),
73             'port'           => $mysqlPort,
74             'charset'        => 'utf8mb4',
75             'collation'      => 'utf8mb4_unicode_ci',
76             // Prefixes are only semi-supported and may be unstable
77             // since they are not tested as part of our automated test suite.
78             // If used, the prefix should not be changed otherwise you will likely receive errors.
79             'prefix'         => env('DB_TABLE_PREFIX', ''),
80             'prefix_indexes' => true,
81             'strict'         => false,
82             'engine'         => null,
83             'options'        => extension_loaded('pdo_mysql') ? array_filter([
84                 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
85             ]) : [],
86         ],
87
88         'mysql_testing' => [
89             'driver'         => 'mysql',
90             'url'            => env('TEST_DATABASE_URL'),
91             'host'           => '127.0.0.1',
92             'database'       => 'bookstack-test',
93             'username'       => env('MYSQL_USER', 'bookstack-test'),
94             'password'       => env('MYSQL_PASSWORD', 'bookstack-test'),
95             'port'           => $mysqlPort,
96             'charset'        => 'utf8mb4',
97             'collation'      => 'utf8mb4_unicode_ci',
98             'prefix'         => '',
99             'prefix_indexes' => true,
100             'strict'         => false,
101         ],
102
103     ],
104
105     // Migration Repository Table
106     // This table keeps track of all the migrations that have already run for
107     // your application. Using this information, we can determine which of
108     // the migrations on disk haven't actually been run in the database.
109     'migrations' => 'migrations',
110
111     // Redis configuration to use if set
112     'redis' => $redisConfig ?? [],
113
114 ];