Dotenv connector in TYPO3 CMS

I am trying to use helhum / dotenv-connector in my TYPO3 project.

I have done the following:

my composer.json:

{
    "require": {
        "typo3/cms": "^8.5",
        "helhum/dotenv-connector": "1.0.0",
        "helhum/typo3-console": "^4.1"
    },
    "extra": {
        "helhum/typo3-console": {
            "install-extension-dummy": false
        },
        "typo3/cms": {
            "cms-package-dir": "{$vendor-dir}/typo3/cms",
            "web-dir": "web"
        },
        "helhum/dotenv-connector": {
            "env-dir": "",
            "allow-overrides": true,
            "cache-dir": "var/cache"
        }
    }
}

Then i ran

composer install

After that, I configure TYPO3 with the command

php vendor/bin/typo3cms install:setup

This should be like setting the “normal” mode.

After that I placed .envnext to minecomposer.json

This one .envcontains the following:

TYPO3_CONTEXT="Development"
TYPO3__DB__database="dotenvconnector"
TYPO3__DB__host="127.0.0.1"
TYPO3__DB__password="root"
TYPO3__DB__port="3306"
TYPO3__DB__username="root"

Then I deleted all database information web/typo3conf/LocalConfiguration.phpfrom using the typo3_console command

php vendor/bin/typo3cms configuration:remove DB

Then I started up again composer installand composer update.

When calling TYPO3 in the browser, now it tells me

The requested database connection with the default name is not configured.

So what am I missing? Obviously mine is .envnot analyzed or used at all.

FYI: Cachefile var/cache :

<?php
putenv('TYPO3__DB__database=dotenvconnector');
$_ENV['TYPO3__DB__database'] = 'dotenvconnector';
$_SERVER['TYPO3__DB__database'] = 'dotenvconnector';
putenv('TYPO3__DB__host=localhost');
$_ENV['TYPO3__DB__host'] = 'localhost';
$_SERVER['TYPO3__DB__host'] = 'localhost';
putenv('TYPO3__DB__password=root');
$_ENV['TYPO3__DB__password'] = 'root';
$_SERVER['TYPO3__DB__password'] = 'root';
putenv('TYPO3__DB__port=3306');
$_ENV['TYPO3__DB__port'] = '3306';
$_SERVER['TYPO3__DB__port'] = '3306';
putenv('TYPO3__DB__username=root');
$_ENV['TYPO3__DB__username'] = 'root';
$_SERVER['TYPO3__DB__username'] = 'root';
+4
2

:

AdditionalConfiguration.php

$loader = new Dotenv\Dotenv(__DIR__ . '/../../', '.env.defaults');
$loader->load();
$loader = new Dotenv\Dotenv(__DIR__ . '/../../');
$loader->overload();

, .env.defaults, ( , ), .env /. , .env, Fatals Exceptions.

$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname'] = getenv('TYPO3_DB_NAME');
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host'] = getenv('TYPO3_DB_HOST');
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password'] = getenv('TYPO3_DB_PASSWORD');
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user'] = getenv('TYPO3_DB_USER');

LocalConfiguration.php

return [
'BE' => [
    'debug' => '<set by dotenv>',
    'explicitADmode' => 'explicitAllow',
    'installToolPassword' => '<set by dotenv>',
    'loginSecurityLevel' => 'rsa',
    'sessionTimeout' => '<set by dotenv>',
],
'DB' => [
    'Connections' => [
        'Default' => [
            'charset' => 'utf8',
            'dbname' => '<set by dotenv>',
            'driver' => 'mysqli',
            'host' => '<set by dotenv>',
            'password' => '<set by dotenv>',
            'port' => 3306,
            'user' => '<set by dotenv>',
        ],
    ],
]...

, , .

+5

dotenv .env , TYPO3. getenv php-. TYPO3, php- . , TYPO3.

- , TYPO3.

.env -dotenv-connector-> environment -configuration-loader-> $GLOBALS['TYPO3_CONF_VARS']

https://github.com/helhum/config-loader. https://github.com/helhum/TYPO3-Distribution.

. getenv().

+1

Source: https://habr.com/ru/post/1665958/


All Articles