|
| 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' => array( |
| 80 | + PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false, |
| 81 | + PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), |
| 82 | + ), |
| 83 | + //'options' => extension_loaded('pdo_mysql') ? array_filter([ |
| 84 | + // PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), |
| 85 | + // PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false, |
| 86 | + //]) : [], |
| 87 | + ], |
| 88 | + |
| 89 | + 'mysql_testing' => [ |
| 90 | + 'driver' => 'mysql', |
| 91 | + 'url' => env('TEST_DATABASE_URL'), |
| 92 | + 'host' => '127.0.0.1', |
| 93 | + 'database' => 'bookstack-test', |
| 94 | + 'username' => env('MYSQL_USER', 'bookstack-test'), |
| 95 | + 'password' => env('MYSQL_PASSWORD', 'bookstack-test'), |
| 96 | + 'port' => $mysql_port, |
| 97 | + 'charset' => 'utf8mb4', |
| 98 | + 'collation' => 'utf8mb4_unicode_ci', |
| 99 | + 'prefix' => '', |
| 100 | + 'prefix_indexes' => true, |
| 101 | + 'strict' => false, |
| 102 | + ], |
| 103 | + |
| 104 | + ], |
| 105 | + |
| 106 | + // Migration Repository Table |
| 107 | + // This table keeps track of all the migrations that have already run for |
| 108 | + // your application. Using this information, we can determine which of |
| 109 | + // the migrations on disk haven't actually been run in the database. |
| 110 | + 'migrations' => 'migrations', |
| 111 | + |
| 112 | + // Redis configuration to use if set |
| 113 | + 'redis' => $redisConfig ?? [], |
| 114 | + |
| 115 | +]; |
0 commit comments