Dot Env (.env)
The HumHub's .env file contains environment variables which can overwrite the configuration made in files.
This allows for clean separation of configuration and code.
To enable it, copy the .env.example template to .env:
cp .env.example .env
Important: Make sure that the content of the
.envfile is not accessible to the web by checking file permissions or server configuration.
Configuration File Sequence
HumHub's configuration is built from multiple files, and the .env file has the highest priority, overwriting all other configurations:
- Base Configurations (should not be modified):
protected/humhub/config/common.phpprotected/humhub/config/web.php(for Web application)protected/humhub/config/console.php(for Console application)
- Dynamic Configurations:
protected/config/dynamic.php(only for the database configuration)
- Custom Configurations:
protected/config/common.phpprotected/config/web.php(for Web application)protected/config/console.php(for Console application)
- Environment Variables:
.env
Key Features
-
Array Depth Separator:
Uses__to represent nested keys in arrays. -
Key Conversion:
Converts environment variable segments intocamelCase. -
Automatic Value Normalization:
Supports JSON decoding and boolean value conversion.
Example:
HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__ENABLE_PRETTY_URL=true
HUMHUB_CONFIG__PARAMS__SUPPORTED_LANGUAGES=["en", "de", "fr"]
$config['components']['urlManager']['enablePrettyUrl'] = true;
$config['params']['supportedLanguages'] = ['en', 'de', 'fr'];
- Alias Support:
Maps environment-defined aliases to Yii aliases.
Example:
HUMHUB_ALIASES__WEBROOT=/var/www/app
HUMHUB_ALIASES__UPLOADS=/var/www/app/uploads
Yii::setAlias('@webroot', '/var/www/app');
Yii::setAlias('@uploads', '/var/www/app/uploads');
Supported Prefixes
HUMHUB_DEBUG
Controls Yii's debugging and environment settings.
- When
HUMHUB_DEBUG=true:- Sets
YII_DEBUGtotrue - Sets
YII_ENVtodev
- Sets
- When
HUMHUB_DEBUG=falseor not set:- Sets
YII_DEBUGtofalse - Sets
YII_ENVtoprod
- Sets
HUMHUB_CONFIG
General Yii configuration.
- Example:
Resulting Configuration:
HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__ENABLE_PRETTY_URL=true
HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__SHOW_SCRIPT_NAME=false$config['components']['urlManager']['enablePrettyUrl'] = true;
$config['components']['urlManager']['showScriptName'] = false;
HUMHUB_WEB_CONFIG
Web application-specific configuration.
- Example:
Resulting Configuration:
HUMHUB_WEB_CONFIG__COMPONENTS__ASSET_MANAGER__FORCE_COPY=true$config['components']['assetManager']['forceCopy'] = true;
HUMHUB_CLI_CONFIG
Console application-specific configuration.
- Example:
Resulting Configuration:
HUMHUB_CLI_CONFIG__COMPONENTS__CACHE__CLASS=FileCache$config['components']['cache']['class'] = 'FileCache';
HUMHUB_FIXED_SETTINGS
Defines fixed settings under params['fixed-settings'].
- Example:
Resulting Configuration:
HUMHUB_FIXED_SETTINGS__EXAMPLE1__EXAMPLE2=Something$config['params']['fixed-settings']['example1']['example2'] = 'Something';
Example Configuration
HUMHUB_FIXED_SETTINGS__EXAMPLE1__EXAMPLE2=Something
HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__ENABLE_PRETTY_URL=true
HUMHUB_WEB_CONFIG__COMPONENTS__ASSET_MANAGER__FORCE_COPY=true
HUMHUB_CLI_CONFIG__COMPONENTS__CACHE__CLASS=FileCache
HUMHUB_ALIASES__WEBROOT=/var/www/app
Resulting Configuration:
$config = [
'params' => [
'fixed-settings' => [
'example1' => [
'example2' => 'Something',
],
],
],
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
],
'assetManager' => [
'forceCopy' => true,
],
'cache' => [
'class' => 'FileCache',
],
],
'aliases' => [
'@webroot' => '/var/www/app',
],
];