Benutzung von .env in TYPO3

Das ist eine 1 zu 1 Kopie, von diesem Snippet https://gitlab.apfelkiste.eu/snippets/1
da ich mir den Link nicht merken kann, das ganze hier noch mal gespeichert 🙂

Mit Hilfe einer .env-File können empfindliche Einstellungen wie Passwörter bzw. Einstellungen, die sich je System ändern zentral und außerhalb des Repositories abgelegt werden.

Composer-Install

composer req helhum/dotenv-connector 

.env-File

TYPO3_CONTEXT="Development"
TYPO3__DB__database="base9"
TYPO3__DB__host="127.0.0.1"
TYPO3__DB__password="geheim"
TYPO3__DB__port="3306" 
TYPO3__DB__username="root" 
SOLR_PASSWORD="psst!geheim" 

public/typo3conf/LocalConfiguration.php

...
'DB' => [
    'Connections' => [
        'Default' => [
            'charset' => 'utf8mb4',
            'dbname' => '<set by dotenv>',
            'driver' => 'mysqli',
            'host' => '<set by dotenv>',
            'password' => '<set by dotenv>',
            'port' => '<set by dotenv>',
            'tableoptions' => [
                'charset' => 'utf8mb4',
                'collate' => 'utf8mb4_unicode_ci',
            ],
            'user' => '<set by dotenv>',
        ],
    ],
],

public/typo3conf/AdditionalConfiguration.php

<?php
$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');

Benutzung in Site-Config

rootPageId: 1
base: 'https://%env(SAAROBERMOSEL_DOMAIN)%/'

Benutzung von TYPO3_CONTEXT in typoscript

# Einstellungen für Entwicklunssysteme
[applicationContext = Development]
  config.absRefPrefix = http://projekt.dev/
  config.admPanel = 1
  [...]
[end]

Benutzung im Typoscript (Werte)

plugin.tx_solr.solr {
	read {
		password = TEXT
		password {
			data = getenv:SOLR_PASSWORD
		}
	}
}