This is my dotenv setup:
- my .env file lives in the flarum root directory
- i have different config files stored under
config/ similar to what laravel usually does
- my config.php loads each config file and assigns it to the return array
Here it goes:
<?php
use Dotenv\Dotenv;
(new Dotenv(__DIR__))->load();
$app = include __DIR__ . '/config/app.php';
$database = include __DIR__ . '/config/database.php';
return [
'app' => $app,
'database' => $database,
'url' => array_get($app, 'url'),
'debug' => array_get($app, 'debug', false),
];
config/app.php
<?php
return [
'env' => env('APP_ENV', 'production'),
'url' => env('APP_URL', 'https://bokt.nl'),
'debug' => env('APP_DEBUG', false),
];
config/database.php
<?php
return [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'bokt_flarum'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => env('DB_PREFIX', ''),
'strict' => true,
'engine' => null,
'options' => [
PDO::ATTR_PERSISTENT => true,
]
];
I have more configuration files (queue and session), that's also a reason I separated them.
The drawback of this method is that it will not work if your forum isn't installed yet. Your database has to exist and has to be installed.