Skip to content

Instantly share code, notes, and snippets.

@htuscher
Created January 16, 2019 12:49
Show Gist options
  • Save htuscher/06f64c1687e42b9b345dccc295ed9cab to your computer and use it in GitHub Desktop.
Save htuscher/06f64c1687e42b9b345dccc295ed9cab to your computer and use it in GitHub Desktop.
AdditionalConfiguration with Redis Cache and ENV variables
<?php
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Core\Bootstrap;
// For docker we log to syslog
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::WARNING => [
\TYPO3\CMS\Core\Log\Writer\SyslogWriter::class => []
]
];
$bootstrap = Bootstrap::getInstance();
// Use Redis cache
ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'], [
'cache_pages' => [
'backend' => \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class,
'options' => [
'hostname' => 'redis',
'defaultLifetime' => 86400,
'database' => 0
]
],
'cache_pagesection' => [
'backend' => \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class,
'options' => [
'hostname' => 'redis',
'defaultLifetime' => 86400,
'database' => 1
]
],
'cache_hash' => [
'backend' => \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class,
'options' => [
'hostname' => 'redis',
'defaultLifetime' => 86400,
'database' => 2
]
],
'extbase_object' => [
'backend' => \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class,
'options' => [
'hostname' => 'redis',
'defaultLifetime' => 86400,
'database' => 3
]
],
'extbase_reflection' => [
'backend' => \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class,
'options' => [
'hostname' => 'redis',
'defaultLifetime' => 86400,
'database' => 4
]
]
]);
if ($bootstrap->getApplicationContext()->isDevelopment()) {
$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] = TRUE;
$GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] = TRUE;
$GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword'] = md5('local');
$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '*';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog'] = 'file';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'] = 1;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] = TRUE;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'] = 1;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'] = 0;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'] = '28674';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['l10n']['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\NullBackend';
}
/**
* Configurations that can be set by Docker environment variables
*/
if (getenv('MYSQL_USER')) {
$GLOBALS['TYPO3_CONF_VARS']['DB']['username'] = getenv('MYSQL_USER');
}
if (getenv('MYSQL_PASSWORD')) {
$GLOBALS['TYPO3_CONF_VARS']['DB']['password'] = getenv('MYSQL_PASSWORD');
}
if (getenv('MYSQL_DB')) {
$GLOBALS['TYPO3_CONF_VARS']['DB']['database'] = getenv('MYSQL_DB');
}
if (getenv('MYSQL_SERVICENAME')) {
$GLOBALS['MYSQL_SERVICENAME']['DB']['host'] = getenv('MYSQL_SERVICENAME');
}
if (getenv('MYSQL_PORT')) {
$GLOBALS['MYSQL_PORT']['DB']['port'] = getenv('MYSQL_PORT');
}
if (getenv('TRUSTED_HOSTS')) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = getenv('TRUSTED_HOSTS');
}
if (getenv('USE_MAILHOG')) {
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport'] = 'smtp';
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport_smtp_server'] = 'mail:1025';
}
if (getenv('SENTRY_DSN')) {
$sentryConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['sentry_client']);
$sentryConfig['dsn'] = getenv('SENTRY_DSN');
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['sentry_client'] = serialize($sentryConfig);
}
/**
* !!! IMPORTANT !!!
*
* To enable your local configuration add
* one or more files in conf.d as they are
* loaded automatically.
*/
$configurationFiles = GeneralUtility::getFilesInDir(GeneralUtility::getFileAbsFileName('typo3conf/conf.d/'), 'php', TRUE);
foreach ($configurationFiles as $file) {
require_once($file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment