]> BookStack Code Mirror - bookstack/blob - app/Config/database.php
Removed old str_random functions from seeders
[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
15     $redisDefaults = ['host' => '127.0.0.1', 'port' => '6379', 'database' => '0', 'password' => null];
16     $redisServers = explode(',', trim(env('REDIS_SERVERS', '127.0.0.1:6379:0'), ','));
17     $redisConfig = ['client' => 'predis'];
18     $cluster = count($redisServers) > 1;
19
20     if ($cluster) {
21         $redisConfig['clusters'] = ['default' => []];
22     }
23
24     foreach ($redisServers as $index => $redisServer) {
25         $redisServerDetails = explode(':', $redisServer);
26
27         $serverConfig = [];
28         $configIndex = 0;
29         foreach ($redisDefaults as $configKey => $configDefault) {
30             $serverConfig[$configKey] = ($redisServerDetails[$configIndex] ?? $configDefault);
31             $configIndex++;
32         }
33
34         if ($cluster) {
35             $redisConfig['clusters']['default'][] = $serverConfig;
36         } else {
37             $redisConfig['default'] = $serverConfig;
38         }
39     }
40 }
41
42 // MYSQL
43 // Split out port from host if set
44 $mysql_host = env('DB_HOST', 'localhost');
45 $mysql_host_exploded = explode(':', $mysql_host);
46 $mysql_port = env('DB_PORT', 3306);
47 if (count($mysql_host_exploded) > 1) {
48     $mysql_host = $mysql_host_exploded[0];
49     $mysql_port = intval($mysql_host_exploded[1]);
50 }
51
52 return [
53
54     // Default database connection name.
55     // Options: mysql, mysql_testing
56     'default' => env('DB_CONNECTION', 'mysql'),
57
58     // Available database connections
59     // Many of those shown here are unsupported by BookStack.
60     'connections' => [
61
62         'mysql' => [
63             'driver'    => 'mysql',
64             'url' => env('DATABASE_URL'),
65             'host'      => $mysql_host,
66             'database'  => env('DB_DATABASE', 'forge'),
67             'username'  => env('DB_USERNAME', 'forge'),
68             'password'  => env('DB_PASSWORD', ''),
69             'unix_socket' => env('DB_SOCKET', ''),
70             'port'      => $mysql_port,
71             'charset'   => 'utf8mb4',
72             'collation' => 'utf8mb4_unicode_ci',
73             'prefix'    => '',
74             'prefix_indexes' => true,
75             'strict'    => false,
76             'engine' => null,
77             'options' => extension_loaded('pdo_mysql') ? array_filter([
78                 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
79             ]) : [],
80         ],
81
82         'mysql_testing' => [
83             'driver'    => 'mysql',
84             'url' => env('TEST_DATABASE_URL'),
85             'host'      => '127.0.0.1',
86             'database'  => 'bookstack-test',
87             'username'  => env('MYSQL_USER', 'bookstack-test'),
88             'password'  => env('MYSQL_PASSWORD', 'bookstack-test'),
89             'charset'   => 'utf8mb4',
90             'collation' => 'utf8mb4_unicode_ci',
91             'prefix'    => '',
92             'prefix_indexes' => true,
93             'strict'    => false,
94         ],
95
96     ],
97
98     // Migration Repository Table
99     // This table keeps track of all the migrations that have already run for
100     // your application. Using this information, we can determine which of
101     // the migrations on disk haven't actually been run in the database.
102     'migrations' => 'migrations',
103
104     // Redis configuration to use if set
105     'redis' => env('REDIS_SERVERS', false) ? $redisConfig : [],
106
107 ];