-
-
Notifications
You must be signed in to change notification settings - Fork 531
Open
Labels
featureRequest about implementing a brand new function or possibility.Request about implementing a brand new function or possibility.
Description
Feature request
Summary
Allow defining core site settings (currently stored in core/config/config.inc.php
) via .env
file or environment variables.
Why is it needed?
Right now, important configuration values are hardcoded in config.inc.php
. This causes problems such as:
- Difficulties managing different environments (development, staging, production).
- Sensitive data like database credentials being stored in tracked files.
- Complicated deployments since configs must be manually edited per environment.
Suggested solution(s)
- Load configuration values from
.env
file first. - If a value is not defined in
.env
, fall back to the existingconfig.inc.php
. - Document supported
.env
keys (e.g.,DB_HOST
,DB_NAME
,DB_USER
,DB_PASS
).
Related issue(s)/PR(s)
Not currently related to any existing issues/PRs (to my knowledge).
here is a dirty example of how I implemented it, of course, it is probably better to move the class initialization and helper functions to another file. Example implementation (for illustration purposes only):
// require project general composer
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
// Include .env from project root
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__, 2));
$dotenv->safeLoad();
// Laravel-like env() function, can use in php/snippet
if (!function_exists('env')) {
function env($key, $default = null)
{
$value = $_ENV[$key] ?? null;
if ($value === null) return $default;
if (strtolower($value) === 'true') return true;
if (strtolower($value) === 'false') return false;
if (strtolower($value) === 'null') return null;
return $value;
}
}
$database_type = env('DB_TYPE', 'mysql');
$database_server = env('DB_HOST', 'localhost');
$database_user = env('DB_USER');
$database_password = env('DB_PASSWORD');
$database_connection_charset = env('DB_CHARSET', 'utf8mb4');
$database_name = env('DB_NAME');
$table_prefix = env('DB_PREFIX');
$database_dsn = 'mysql:host=' . $database_server . ';dbname=' . $database_name . ';charset=' . $database_connection_charset;
$config_options = ['override_table' => 'MyISAM'];
$driver_options = [];
Ruslan-Aleev
Metadata
Metadata
Assignees
Labels
featureRequest about implementing a brand new function or possibility.Request about implementing a brand new function or possibility.