{"record":{"id":"abc68a80123687e1","repo":"yiisoft/yii2","slug":"unable-to-determine-the-entry-script-file-path","errorCode":null,"errorMessage":"Unable to determine the entry script file path.","messagePattern":"Unable to determine the entry script file path\\.","errorType":"exception","errorClass":"InvalidConfigException","httpStatus":null,"severity":"error","filePath":"framework/base/Request.php","lineNumber":65,"sourceCode":"     * @param bool $value the value indicating whether the current request is made via command line\n     */\n    public function setIsConsoleRequest($value)\n    {\n        $this->_isConsoleRequest = $value;\n    }\n\n    /**\n     * Returns entry script file path.\n     * @return string entry script file path (processed w/ realpath())\n     * @throws InvalidConfigException if the entry script file path cannot be determined automatically.\n     */\n    public function getScriptFile()\n    {\n        if ($this->_scriptFile === null) {\n            if (isset($_SERVER['SCRIPT_FILENAME'])) {\n                $this->setScriptFile($_SERVER['SCRIPT_FILENAME']);\n            } else {\n                throw new InvalidConfigException('Unable to determine the entry script file path.');\n            }\n        }\n\n        return $this->_scriptFile;\n    }\n\n    /**\n     * Sets the entry script file path.\n     * The entry script file path can normally be determined based on the `SCRIPT_FILENAME` SERVER variable.\n     * However, for some server configurations, this may not be correct or feasible.\n     * This setter is provided so that the entry script file path can be manually specified.\n     * @param string $value the entry script file path. This can be either a file path or a [path alias](guide:concept-aliases).\n     * @throws InvalidConfigException if the provided entry script file path is invalid.\n     */\n    public function setScriptFile($value)\n    {\n        $scriptFile = realpath(Yii::getAlias($value));\n        if ($scriptFile !== false && is_file($scriptFile)) {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/base/Request.php#L47-L83","documentation":"yii\\base\\Request::getScriptFile() lazily caches the entry script path from $_SERVER['SCRIPT_FILENAME'] and throws InvalidConfigException when that superglobal key is unset. The web Request assumes it was created inside a real HTTP request; any context that constructs or reuses the component outside one (queue workers, CLI scripts, tests) lacks the variable.","triggerScenarios":"A console command or queue job bootstrapped from the web config calls UrlManager/asset helpers that reach getScriptFile(); unit tests do new \\yii\\web\\Request() directly; a non-standard SAPI or sanitized $_SERVER strips SCRIPT_FILENAME; long-running servers (Swoole/ReactPHP) reuse the component across synthetic requests.","commonSituations":"Queue jobs generating absolute URLs or asset paths for emails; cron tasks reusing the web application config; test harnesses instantiating the component; deployments behind custom routers that repopulate $_SERVER incompletely.","solutions":["Set the value explicitly before use: Yii::$app->request->setScriptFile('@app/web/index.php')","Populate $_SERVER['SCRIPT_FILENAME'] in the worker bootstrap to match the real web entry script","Bootstrap CLI contexts with the console application config (yii\\console\\Request) instead of the web request component","Where only URLs are needed, configure UrlManager's baseUrl/hostInfo explicitly instead of relying on request autodetection"],"exampleFix":"// before (queue worker reusing web config)\n$file = Yii::$app->request->getScriptFile(); // InvalidConfigException: SCRIPT_FILENAME unset\n\n// after\nYii::$app->request->setScriptFile(Yii::getAlias('@app/web/index.php'));\n$file = Yii::$app->request->getScriptFile();","handlingStrategy":"fallback","validationCode":"if (!isset($_SERVER['SCRIPT_FILENAME'])) {\n    Yii::$app->request->setScriptFile(Yii::getAlias('@app/web/index.php'));\n}\n$file = Yii::$app->request->getScriptFile();","typeGuard":null,"tryCatchPattern":"try {\n    $file = Yii::$app->request->getScriptFile();\n} catch (\\yii\\base\\InvalidConfigException $e) {\n    $file = Yii::getAlias('@app/web/index.php');\n    Yii::$app->request->setScriptFile($file);\n}","preventionTips":["Bootstrap CLI/queue processes with the console config instead of the web config","Set SCRIPT_FILENAME (or call setScriptFile) explicitly at worker startup when web components are reused","Prefer path aliases over request-derived script paths in offline contexts"],"tags":["php","yii2","request","cli","server-superglobal"],"backgroundTag":"missing-server-variable","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}