Dot Env (.env)
The HumHub's .env file provides a mechanism for mapping environment variables to the configuration array used by the Yii framework. This allows for clean separation of configuration and code.
Overview
The HumHub's .env file mechanism is not enabled by default. It is designed for advanced users who want to customize their HumHub configuration in a flexible way. To enable it, users can create a .env file by copying the provided .env.example template:
cp .env.example .env
Afterward, users can populate the .env file with their custom configurations.
Important: Be sure that the contents of the
.envfile are not accessible to the web. Make sure to secure it using proper file permissions or server configuration to prevent unauthorized access.
Configuration File Sequence
HumHub's configuration is built from multiple files, and the .env file has the highest priority, overwriting all other configurations.
Sequence of Configuration Files
- Base Configurations:
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
- Custom Configurations:
protected/config/common.phpprotected/config/web.php(for Web application)protected/config/console.php(for Console application)
- Environment Variables:
.env
Key Features
-
Environment-Specific Prefixes:
HUMHUB_FIXED_SETTINGS: Immutable settings.HUMHUB_CONFIG: General Yii configuration.HUMHUB_WEB_CONFIG: Web application-specific configuration.HUMHUB_CLI_CONFIG: Console application-specific configuration.HUMHUB_ALIASES: Yii alias definitions.
-
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. -
Alias Support:
Maps environment-defined aliases to Yii aliases.
Debug Mode
The HUMHUB_DEBUG environment variable controls Yii's debugging and environment settings.
Behavior
- When
HUMHUB_DEBUG=true:- Sets
YII_DEBUGtotrue - Sets
YII_ENVtodev
- Sets
- When
HUMHUB_DEBUG=falseor not set:- Sets
YII_DEBUGtofalse - Sets
YII_ENVtoprod
- Sets
Supported Prefixes
HUMHUB_FIXED_SETTINGS
- Purpose: Defines fixed settings under
params['fixed-settings']. - Example:
Resulting Configuration:
HUMHUB_FIXED_SETTINGS__EXAMPLE1__EXAMPLE2=Something$config['params']['fixed-settings']['example1']['example2'] = 'Something';
HUMHUB_CONFIG
- Purpose: 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
- Purpose: Web application-specific configuration.
- Example:
Resulting Configuration:
HUMHUB_WEB_CONFIG__COMPONENTS__ASSET_MANAGER__FORCE_COPY=true$config['components']['assetManager']['forceCopy'] = true;
HUMHUB_CLI_CONFIG
- Purpose: Console application-specific configuration.
- Example:
Resulting Configuration:
HUMHUB_CLI_CONFIG__COMPONENTS__CACHE__CLASS=FileCache$config['components']['cache']['class'] = 'FileCache';
HUMHUB_ALIASES
- Purpose: Maps aliases for Yii.
- Example:
Resulting Aliases:
HUMHUB_ALIASES__WEBROOT=/var/www/app
HUMHUB_ALIASES__UPLOADS=/var/www/app/uploadsYii::setAlias('@webroot', '/var/www/app');
Yii::setAlias('@uploads', '/var/www/app/uploads');
Value Normalization
-
Boolean Values: Strings like
trueandfalseare converted to booleans.HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__ENABLE_PRETTY_URL=true$config['components']['urlManager']['enablePrettyUrl'] = true; -
JSON Decoding: Strings are decoded into arrays or objects.
HUMHUB_CONFIG__PARAMS__SUPPORTED_LANGUAGES=["en", "de", "fr"]$config['params']['supportedLanguages'] = ['en', 'de', 'fr'];
Example Configuration
Sample .env File
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',
],
];