firefly-iii/config/database.php

160 lines
6.4 KiB
PHP
Raw Permalink Normal View History

2015-02-05 21:39:52 -06:00
<?php
2017-10-21 01:40:00 -05:00
/**
* database.php
2020-03-17 11:06:30 -05:00
* Copyright (c) 2019 james@firefly-iii.org.
2017-10-21 01:40:00 -05:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2017-10-21 01:40:00 -05:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 01:40:00 -05:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 01:40:00 -05:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 01:40:00 -05:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-10-21 01:40:00 -05:00
*/
declare(strict_types=1);
$databaseUrl = getenv('DATABASE_URL');
$host = '';
$username = '';
$password = '';
$database = '';
$port = '';
2017-11-29 09:23:17 -06:00
2020-10-24 09:59:56 -05:00
if (false !== $databaseUrl) {
2017-11-29 09:26:00 -06:00
$options = parse_url($databaseUrl);
2019-09-07 13:44:02 -05:00
$host = $options['host'] ?? 'firefly_iii_db';
$username = $options['user'] ?? 'firefly';
$port = $options['port'] ?? '5432';
$password = $options['pass'] ?? 'secret_firefly_password';
$database = substr($options['path'] ?? '/firefly', 1);
2017-11-29 09:26:00 -06:00
}
2017-11-29 09:23:17 -06:00
2023-12-20 12:39:53 -06:00
// Get SSL parameters from .env file.
2020-05-28 23:16:42 -05:00
$mysql_ssl_ca_dir = envNonEmpty('MYSQL_SSL_CAPATH', null);
$mysql_ssl_ca_file = envNonEmpty('MYSQL_SSL_CA', null);
$mysql_ssl_cert = envNonEmpty('MYSQL_SSL_CERT', null);
$mysql_ssl_key = envNonEmpty('MYSQL_SSL_KEY', null);
$mysql_ssl_ciphers = envNonEmpty('MYSQL_SSL_CIPHER', null);
2020-05-27 04:08:15 -05:00
$mysql_ssl_verify = envNonEmpty('MYSQL_SSL_VERIFY_SERVER_CERT', null);
2020-05-21 17:22:31 -05:00
$mySqlSSLOptions = [];
$useSSL = envNonEmpty('MYSQL_USE_SSL', false);
2023-10-30 01:27:43 -05:00
if (false !== $useSSL && null !== $useSSL && '' !== $useSSL) {
if (null !== $mysql_ssl_ca_dir) {
$mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CAPATH] = $mysql_ssl_ca_dir;
}
if (null !== $mysql_ssl_ca_file) {
$mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CA] = $mysql_ssl_ca_file;
}
if (null !== $mysql_ssl_cert) {
$mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CERT] = $mysql_ssl_cert;
}
if (null !== $mysql_ssl_key) {
$mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_KEY] = $mysql_ssl_key;
}
if (null !== $mysql_ssl_ciphers) {
$mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CIPHER] = $mysql_ssl_ciphers;
}
if (null !== $mysql_ssl_verify) {
$mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $mysql_ssl_verify;
}
}
2020-05-21 17:22:31 -05:00
2015-02-05 21:39:52 -06:00
return [
2020-09-11 23:28:23 -05:00
'default' => envNonEmpty('DB_CONNECTION', 'mysql'),
2015-02-07 03:32:15 -06:00
'connections' => [
2023-05-29 06:56:55 -05:00
'sqlite' => [
2016-11-19 08:55:49 -06:00
'driver' => 'sqlite',
2018-04-26 23:26:37 -05:00
'database' => envNonEmpty('DB_DATABASE', storage_path('database/database.sqlite')),
2016-11-19 08:55:49 -06:00
'prefix' => '',
2015-02-07 03:32:15 -06:00
],
2023-05-29 06:56:55 -05:00
'mysql' => [
2017-09-09 15:32:11 -05:00
'driver' => 'mysql',
2019-09-07 13:44:02 -05:00
'host' => envNonEmpty('DB_HOST', $host),
'port' => envNonEmpty('DB_PORT', $port),
'database' => envNonEmpty('DB_DATABASE', $database),
'username' => envNonEmpty('DB_USERNAME', $username),
'password' => env('DB_PASSWORD', $password),
2017-09-09 15:32:11 -05:00
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
2018-10-17 08:50:43 -05:00
'engine' => 'InnoDB',
2020-05-28 23:16:42 -05:00
'options' => $mySqlSSLOptions,
2015-02-07 03:32:15 -06:00
],
2023-05-29 06:56:55 -05:00
'pgsql' => [
2019-03-02 07:33:46 -06:00
'driver' => 'pgsql',
'host' => envNonEmpty('DB_HOST', $host),
2019-09-07 13:44:02 -05:00
'port' => envNonEmpty('DB_PORT', $port),
2019-03-02 07:33:46 -06:00
'database' => envNonEmpty('DB_DATABASE', $database),
'username' => envNonEmpty('DB_USERNAME', $username),
'password' => env('DB_PASSWORD', $password),
'charset' => 'utf8',
'prefix' => '',
2022-02-28 00:48:58 -06:00
'search_path' => envNonEmpty('PGSQL_SCHEMA', 'public'),
'schema' => envNonEmpty('PGSQL_SCHEMA', 'public'),
2019-03-02 07:33:46 -06:00
'sslmode' => envNonEmpty('PGSQL_SSL_MODE', 'prefer'),
'sslcert' => envNonEmpty('PGSQL_SSL_CERT'),
'sslkey' => envNonEmpty('PGSQL_SSL_KEY'),
'sslrootcert' => envNonEmpty('PGSQL_SSL_ROOT_CERT'),
2015-02-07 03:32:15 -06:00
],
2023-05-29 06:56:55 -05:00
'sqlsrv' => [
2017-09-09 15:32:11 -05:00
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
2015-02-07 03:32:15 -06:00
],
2016-11-19 08:55:49 -06:00
'migrations' => 'migrations',
2019-12-07 23:14:49 -06:00
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer body of commands than a typical key-value system
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
2016-11-19 08:55:49 -06:00
'redis' => [
2019-12-07 23:14:49 -06:00
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'predis'),
2023-12-20 12:39:53 -06:00
// 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
2019-12-07 23:14:49 -06:00
],
2015-02-07 03:32:15 -06:00
'default' => [
2020-08-02 23:24:25 -05:00
'scheme' => envNonEmpty('REDIS_SCHEME', 'tcp'),
'url' => envNonEmpty('REDIS_URL'),
'path' => envNonEmpty('REDIS_PATH'),
'host' => envNonEmpty('REDIS_HOST', '127.0.0.1'),
'port' => envNonEmpty('REDIS_PORT', 6379),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD', null),
2019-12-07 10:44:33 -06:00
'database' => env('REDIS_DB', '0'),
2015-02-07 03:32:15 -06:00
],
2019-12-07 23:14:49 -06:00
'cache' => [
2020-08-02 23:24:25 -05:00
'scheme' => envNonEmpty('REDIS_SCHEME', 'tcp'),
'url' => envNonEmpty('REDIS_URL'),
'path' => envNonEmpty('REDIS_PATH'),
'host' => envNonEmpty('REDIS_HOST', '127.0.0.1'),
'port' => envNonEmpty('REDIS_PORT', 6379),
2022-07-26 22:05:36 -05:00
'username' => env('REDIS_USERNAME'),
2019-12-07 23:14:49 -06:00
'password' => env('REDIS_PASSWORD', null),
'database' => env('REDIS_CACHE_DB', '1'),
],
2015-02-07 03:32:15 -06:00
],
2015-02-05 21:39:52 -06:00
];