{"record":{"id":"25cefa0959583569","repo":"yiisoft/yii2","slug":"the-basepath-configuration-for-the-application-i","errorCode":null,"errorMessage":"The \"basePath\" configuration for the Application is required.","messagePattern":"The \"basePath\" configuration for the Application is required\\.","errorType":"exception","errorClass":"InvalidConfigException","httpStatus":null,"severity":"error","filePath":"framework/base/Application.php","lineNumber":224,"sourceCode":"\n    /**\n     * Pre-initializes the application.\n     * This method is called at the beginning of the application constructor.\n     * It initializes several important application properties.\n     * If you override this method, please make sure you call the parent implementation.\n     * @param array $config the application configuration\n     * @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing.\n     */\n    public function preInit(&$config)\n    {\n        if (!isset($config['id'])) {\n            throw new InvalidConfigException('The \"id\" configuration for the Application is required.');\n        }\n        if (isset($config['basePath'])) {\n            $this->setBasePath($config['basePath']);\n            unset($config['basePath']);\n        } else {\n            throw new InvalidConfigException('The \"basePath\" configuration for the Application is required.');\n        }\n\n        if (isset($config['vendorPath'])) {\n            $this->setVendorPath($config['vendorPath']);\n            unset($config['vendorPath']);\n        } else {\n            // set \"@vendor\"\n            $this->getVendorPath();\n        }\n        if (isset($config['runtimePath'])) {\n            $this->setRuntimePath($config['runtimePath']);\n            unset($config['runtimePath']);\n        } else {\n            // set \"@runtime\"\n            $this->getRuntimePath();\n        }\n\n        if (isset($config['timeZone'])) {","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/base/Application.php#L206-L242","documentation":"The second mandatory key enforced by Application::preInit(): 'basePath' is required in the config (there is no alias fallback in preInit itself; the value may be an alias path). setBasePath() stores it and defines the @app alias from which @runtime, @vendor and other derived aliases are built. Without the key the application cannot start and InvalidConfigException is thrown before any component initializes.","triggerScenarios":"Constructing an Application whose config has 'id' but no 'basePath'; config refactors that moved basePath into a params file; a config file that returns only part of the array; bootstrapping Yii inside queue workers or PHPUnit from a hand-written config.","commonSituations":"Custom micro-applications outside the standard templates; a typo or wrong case in the key ('basepath' - config keys are case-sensitive); multi-app setups where the console variant of the config lost the key.","solutions":["Add 'basePath' => dirname(__DIR__) - the conventional value in Yii templates - to the config","Check that the entry script's require(...) loads the intended config file and that the file returns the full array","If config is built programmatically, assert the required keys before constructing the app"],"exampleFix":"// before\n$app = new \\yii\\web\\Application(['id' => 'api', 'components' => require __DIR__ . '/components.php']);\n\n// after\n$app = new \\yii\\web\\Application([\n    'id' => 'api',\n    'basePath' => dirname(__DIR__),\n    'components' => require __DIR__ . '/components.php',\n]);","handlingStrategy":"validation","validationCode":"if (!isset($config['id'], $config['basePath'])) {\n    throw new \\InvalidArgumentException('Application config requires both id and basePath');\n}\n$app = new \\yii\\web\\Application($config);","typeGuard":null,"tryCatchPattern":"try {\n    $app = new \\yii\\web\\Application($config);\n} catch (\\yii\\base\\InvalidConfigException $e) {\n    error_log('Application bootstrap failed; check config keys id/basePath in ' . $configFile);\n    throw $e;\n}","preventionTips":["Reuse the same base config for web and console and only overlay entry-specific keys","Assert required keys in config builders used by tests and workers","Remember config keys are case-sensitive: 'basePath', not 'basepath'"],"tags":["configuration","application","bootstrap","path"],"backgroundTag":"missing-required-config-key","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}