Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .env file configuration to documentation #159

Open
marc-farre opened this issue Nov 25, 2024 · 7 comments
Open

Add .env file configuration to documentation #159

marc-farre opened this issue Nov 25, 2024 · 7 comments
Assignees

Comments

@marc-farre
Copy link
Contributor

I think we should mention the new .env file in:

@luke-
Copy link
Contributor

luke- commented Nov 25, 2024

@Semir1212 @mbumpalumpa Can you take care of it?

@Semir1212
Copy link
Collaborator

@marc-farre I am having difficulties understanding the topic. Could you please write a few lines for the documentation so that we don't get it wrong?

@marc-farre
Copy link
Contributor Author

@Semir1212 it's about the new .env file: https://github.com/humhub/humhub/blob/develop/.env.example
The idea is to update the doc about the configuration file, because since 1.17:

  • part of the configuration settings are done in this new file instead of protected/config/common.php
  • upgrading HH manually requires keeping this file alongside with the .htaccess.

But I'm seeing that there is already a similar issue: https://github.com/humhub/humhub-internal/issues/437

And an open PR where most of the work is already done: https://github.com/humhub/documentation/pull/143/files

However, the 2 mentioned pages are not included in this PR:
https://docs.humhub.org/docs/admin/advanced-configuration
https://docs.humhub.org/docs/admin/updating#upgrade-manually -> Restore individual files

@Semir1212
Copy link
Collaborator

@marc-farre Thank you, could you please look into the PR and add the missing parts?

@luke-
Copy link
Contributor

luke- commented Dec 19, 2024

@gevorgmansuryan Can you please help here?

@gevorgmansuryan
Copy link
Contributor

gevorgmansuryan commented Dec 28, 2024

HumHub's .env Documentation

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 .env file are not accessible to the web. Make sure to secure it using proper file permissions or server configuration to prevent unauthorized access.


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 into camelCase.

  • 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_DEBUG to true.
    • Sets YII_ENV to dev.
  • When HUMHUB_DEBUG=false or not set:
    • Sets YII_DEBUG to false.
    • Sets YII_ENV to prod.

Example

HUMHUB_DEBUG=true

Resulting Constants:

define('YII_DEBUG', true);
define('YII_ENV', 'dev');
HUMHUB_DEBUG=false

Resulting Constants:

defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');

Supported Prefixes

HUMHUB_FIXED_SETTINGS

  • Purpose: Defines fixed settings under params['fixed-settings'].
  • Example:
    HUMHUB_FIXED_SETTINGS__APP__NAME=MyApp
    HUMHUB_FIXED_SETTINGS__APP__VERSION=1.0.0
    Resulting Configuration:
    $config['params']['fixed-settings']['app']['name'] = 'MyApp';
    $config['params']['fixed-settings']['app']['version'] = '1.0.0';

HUMHUB_CONFIG

  • Purpose: General Yii configuration.
  • Example:
    HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__ENABLE_PRETTY_URL=true
    HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__SHOW_SCRIPT_NAME=false
    Resulting Configuration:
    $config['components']['urlManager']['enablePrettyUrl'] = true;
    $config['components']['urlManager']['showScriptName'] = false;

HUMHUB_WEB_CONFIG

  • Purpose: Web application-specific configuration.
  • Example:
    HUMHUB_WEB_CONFIG__COMPONENTS__ASSET_MANAGER__FORCE_COPY=true
    Resulting Configuration:
    $config['components']['assetManager']['forceCopy'] = true;

HUMHUB_CLI_CONFIG

  • Purpose: Console application-specific configuration.
  • Example:
    HUMHUB_CLI_CONFIG__COMPONENTS__CACHE__CLASS=FileCache
    Resulting Configuration:
    $config['components']['cache']['class'] = 'FileCache';

HUMHUB_ALIASES

  • Purpose: Maps aliases for Yii.
  • Example:
    HUMHUB_ALIASES__WEBROOT=/var/www/app
    HUMHUB_ALIASES__UPLOADS=/var/www/app/uploads
    Resulting Aliases:
    Yii::setAlias('@webroot', '/var/www/app');
    Yii::setAlias('@uploads', '/var/www/app/uploads');

Value Normalization

  • Boolean Values:
    Strings like true and false are 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__APP__NAME=MyApp
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' => [
            'app' => [
                'name' => 'MyApp',
            ],
        ],
    ],
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
        ],
        'assetManager' => [
            'forceCopy' => true,
        ],
        'cache' => [
            'class' => 'FileCache',
        ],
    ],
    'aliases' => [
        '@webroot' => '/var/www/app',
    ],
];

@gevorgmansuryan
Copy link
Contributor

@luke- @Semir1212 pls check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants