Feature request: ability to customize path to .env #11894
-
Being able to customize the path to ExampleThis is the (simplified) directory structure that I have for our GH repo template: .
├── .env
├── composer.json
├── composer.lock
├── src
│ ├── assets
│ ├── bootstrap.php
│ ├── config
│ ├── craft
│ ├── modules
│ ├── plugins
│ ├── storage
│ ├── templates
│ └── web
└── vendor/
Moving .env works completely fine by just editing <?php
/**
* Shared bootstrap file
*/
// Define path constants
define('CRAFT_BASE_PATH', __DIR__);
define('DOTENV_PATH', dirname(CRAFT_BASE_PATH, 1));
define('CRAFT_COMPOSER_PATH', dirname(CRAFT_BASE_PATH, 1) . '/composer.json');
define('CRAFT_VENDOR_PATH', dirname(CRAFT_BASE_PATH, 1) . '/vendor');
// Load Composer's autoloader
require_once CRAFT_VENDOR_PATH . '/autoload.php';
if (class_exists(Dotenv\Dotenv::class) && file_exists(DOTENV_PATH . '/.env')) {
// By default, this will allow .env file values to override environment variables
// with matching names. Use `createUnsafeImmutable` to disable this.
Dotenv\Dotenv::createUnsafeMutable(DOTENV_PATH)->safeLoad();
} However Please, pretty please could we have a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Just added support for a Alternatively, you can point $basePath = __DIR__;
// Define path constants
define('CRAFT_BASE_PATH', dirname($basePath));
define('CRAFT_CONFIG_PATH', "$basePath/config");
define('CRAFT_STORAGE_PATH', "$basePath/storage");
define('CRAFT_TEMPLATES_PATH', "$basePath/templates"); |
Beta Was this translation helpful? Give feedback.
Just added support for a
CRAFT_DOTENV_PATH
constant, for Craft 4.3. (e28fc5d)Alternatively, you can point
CRAFT_BASE_PATH
to the top level directory, and override theconfig/
,storage
andtemplates/
directory path constants (rather thanCRAFT_COMPOSER_PATH
andCRAFT_VENDOR_PATH
):