Skip to content

Instantly share code, notes, and snippets.

@davidhellmann
Created July 18, 2023 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidhellmann/0c4f961a531b8d57c52288edaee36b6a to your computer and use it in GitHub Desktop.
Save davidhellmann/0c4f961a531b8d57c52288edaee36b6a to your computer and use it in GitHub Desktop.
<?php
/**
* Yii Application Config
*
* Edit this file at your own risk!
*
* The array returned by this file will get merged with
* vendor/craftcms/cms/src/config/app.php and app.[web|console].php, when
* Craft's bootstrap script is defining the configuration for the entire
* application.
*
* You can define custom modules and system components, and even override the
* built-in system components.
*
* If you want to modify the application config for *only* web requests or
* *only* console requests, create an app.web.php or app.console.php file in
* your config/ folder, alongside this one.
*/
use craft\helpers\App;
return [
'*' => [
'id' => App::env('CRAFT_APP_ID') ?: 'CraftCMS',
'modules' => [
'site-module' => [
'class' => \modules\sitemodule\SiteModule::class,
],
],
'bootstrap' => ['site-module'],
'components' => [
'db' => function () {
$config = craft\helpers\App::dbConfig();
$config['enableSchemaCache'] = true;
$config['schemaCacheDuration'] = 60 * 60 * 24; // 1 day
return Craft::createObject($config);
},
'deprecator' => [
'throwExceptions' => App::env('HARD_MODE') ?: false,
],
'queue' => [
'class' => craft\queue\Queue::class,
'ttr' => 10 * 60,
],
'redis' => [
'class' => yii\redis\Connection::class,
'hostname' => App::env('REDIS_HOSTNAME'),
'port' => App::env('REDIS_PORT'),
'database' => App::env('REDIS_DEFAULT_DB'),
],
'cache' => [
'class' => yii\redis\Cache::class,
'keyPrefix' => '_' . App::env('CRAFT_APP_ID') . '_CACHE_' ?: 'CraftCMS_CACHE_',
'defaultDuration' => 86400,
'redis' => 'redis',
],
'mutex' => static function() {
$config = [
'class' => craft\mutex\Mutex::class,
'mutex' => [
'class' => yii\redis\Mutex::class,
// set the max duration to 15 minutes for console requests
'expire' => Craft::$app->request->isConsoleRequest ? 900 : 30,
'redis' => [
'hostname' => App::env('REDIS_HOSTNAME') ?: 'localhost',
'port' => App::env('REDIS_PORT'),
'password' => App::env('REDIS_PASSWORD') ?: null,
'database' => App::env('REDIS_DEFAULT_DB'),
],
],
];
// Return the initialized component:
return Craft::createObject($config);
},
],
],
'production' => [],
'staging' => [],
'dev' => [],
];
<?php
/**
* Yii Web Application Config
*
* Edit this file at your own risk!
*
* The array returned by this file will get merged with
* vendor/craftcms/cms/src/config/app.php and app.[web|console].php, when
* Craft's bootstrap script is defining the configuration for the entire
* application.
*
* You can define custom modules and system components, and even override the
* built-in system components.
*
* This application config is applied only for *only* web requests
*/
use craft\helpers\App;
return [
'components' => [
'session' => static function () {
// Get the default component config
$config = App::sessionConfig();
// Override the class to use Redis' session class and our config settings
$config['class'] = yii\redis\Session::class;
$config['keyPrefix'] = '_' . App::env('CRAFT_APP_ID') . '_SESSION_' ?: 'CraftCMS_SESSION_';
$config['redis'] = [
'hostname' => App::env('REDIS_HOSTNAME'),
'port' => App::env('REDIS_PORT'),
'database' => App::env('REDIS_CRAFT_DB'),
];
// Instantiate and return it
return Craft::createObject($config);
},
],
];
<?php
/**
* General Configuration
*
* All of your system's general configuration settings go in here. You can see a
* list of the available settings in vendor/craftcms/cms/src/config/GeneralConfig.php.
*
* @see \craft\config\GeneralConfig
*/
use craft\helpers\App;
return [
'craftEnv' => App::env('CRAFT_ENVIRONMENT') ?: 'dev',
'localDevPerformance' => (bool)App::env('LOCAL_DEV_PERFORMANCE') ?: null,
'dominantColor' => '#efebea',
];
<?php
use craft\config\GeneralConfig;
use craft\helpers\App;
$isDev = App::env('CRAFT_ENVIRONMENT') === 'dev';
$isProd = App::env('CRAFT_ENVIRONMENT') === 'production';
$config = GeneralConfig::create()
->devMode($isDev)
->allowUpdates($isDev)
->allowAdminChanges($isDev)
->enableTemplateCaching(!$isDev)
->enableGraphqlCaching(!$isDev)
->defaultWeekStartDay(1)
->isSystemLive(1)
->backupOnUpdate(0)
->runQueueAutomatically(1)
->cacheDuration(0)
->maxRevisions(10)
->defaultTokenDuration(86400)
->enableCsrfProtection(1)
->limitAutoSlugsToAscii(1)
->convertFilenamesToAscii(true)
->generateTransformsBeforePageLoad(true)
->maxCachedCloudImageSize(3000)
->maxUploadFileSize('100M')
->omitScriptNameInUrls(true)
->useEmailAsUsername(false)
->usePathInfo(true)
->preventUserEnumeration(true)
->errorTemplatePrefix('errors/')
->defaultSearchTermOptions([
'subLeft' => true,
'subRight' => true,
])
->testToEmailAddress(App::env('TEST_MAIL') ?: null)
->resourceBasePath(App::env('WEB_ROOT_PATH') . '/cpresources')
->aliases([
'@assetsUrl' => App::env('ASSETS_URL'),
'@web' => App::env('SITE_URL'),
'@webroot' => App::env('WEB_ROOT_PATH'),
])
->allowedFileExtensions(['jpg', 'png', 'jpeg', 'gif', 'svg', 'mp4', 'wov', 'mp3', 'wav', 'pdf', 'zip', 'csv', 'rar'])
->omitScriptNameInUrls();
if ($isProd) {
$config->disabledPlugins([
'dumper', 'elements-panel', 'blitz-recommendations', 'cp-field-inspect'
]);
}
if (!$isProd) {
$config->disallowRobots();
}
return $config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment