{"record":{"id":"9f6c8f7642b8ebcd","repo":"symfony/http-kernel","slug":"unable-to-create-the-storage-directory-s","errorCode":null,"errorMessage":"Unable to create the storage directory (%s).","messagePattern":"Unable to create the storage directory \\((.+?)\\)\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Profiler/FileProfilerStorage.php","lineNumber":41,"sourceCode":"     */\n    private string $folder;\n\n    /**\n     * Constructs the file storage using a \"dsn-like\" path.\n     *\n     * Example : \"file:/path/to/the/storage/folder\"\n     *\n     * @throws \\RuntimeException\n     */\n    public function __construct(string $dsn)\n    {\n        if (!str_starts_with($dsn, 'file:')) {\n            throw new \\RuntimeException(\\sprintf('Please check your configuration. You are trying to use FileStorage with an invalid dsn \"%s\". The expected format is \"file:/path/to/the/storage/folder\".', $dsn));\n        }\n        $this->folder = substr($dsn, 5);\n\n        if (!is_dir($this->folder) && !@mkdir($this->folder, 0o777, true) && !is_dir($this->folder)) {\n            throw new \\RuntimeException(\\sprintf('Unable to create the storage directory (%s).', $this->folder));\n        }\n    }\n\n    /**\n     * @param-immediately-invoked-callable $filter\n     */\n    public function find(?string $ip, ?string $url, ?int $limit, ?string $method, ?int $start = null, ?int $end = null, ?string $statusCode = null, ?\\Closure $filter = null): array\n    {\n        $file = $this->getIndexFilename();\n\n        if (!file_exists($file)) {\n            return [];\n        }\n\n        $file = fopen($file, 'r');\n        fseek($file, 0, \\SEEK_END);\n\n        $result = [];","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Profiler/FileProfilerStorage.php#L23-L59","documentation":"FileProfilerStorage throws this RuntimeException in its constructor when the storage folder taken from the DSN cannot be created. The constructor requires a DSN of the form 'file:/path/to/storage'; it attempts a recursive mkdir only if the directory does not already exist, then re-checks is_dir to handle races. If mkdir fails (permissions, read-only filesystem, path occupied by a file), this error is raised.","triggerScenarios":"Constructing FileProfilerStorage with a 'file:...' DSN whose target path cannot be created: parent directory not writable by the PHP user, disk full, path exists as a regular file, or open_basedir/SELinux blocking mkdir.","commonSituations":"Misconfigured profiler DSN in a Symfony app (framework.profiler storage DSN or PROFILE_DSN env), containers where var/cache is read-only or owned by another user, storage on an NFS/immutable volume, or a stale file occupying the directory path.","solutions":["Verify the DSN starts with 'file:' and the path after it is absolute and correct (e.g. file:/var/cache/profiler).","Create the directory manually and grant write access to the PHP/PHP-FPM user: mkdir -p /var/cache/profiler && chown www-data:www-data /var/cache/profiler.","Check the path is not an existing file and the filesystem is writable (not a read-only mount, not full).","Check open_basedir / SELinux / AppArmor restrictions that block mkdir at that path.","If disk storage is not workable, switch the DSN to another profiler storage backend (e.g. redis:)."],"exampleFix":"// before\n$storage = new FileProfilerStorage('file:/var/cache/profiler'); // dir missing, www-data cannot write /var/cache\n// after\n// $ mkdir -p /var/cache/profiler && chown www-data:www-data /var/cache/profiler\n$storage = new FileProfilerStorage('file:/var/cache/profiler');","handlingStrategy":"validation","validationCode":"$dsn = 'file:/var/cache/profiler';\nif (!str_starts_with($dsn, 'file:')) {\n    throw new \\InvalidArgumentException('Profiler DSN must start with \"file:\"');\n}\n$dir = substr($dsn, 5);\nif ($dir === '' || (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir))) {\n    throw new \\RuntimeException(\"Cannot create profiler storage dir: {$dir}\");\n}","typeGuard":"function isUsableFileDsn(string $dsn): bool {\n    if (!str_starts_with($dsn, 'file:')) return false;\n    $dir = substr($dsn, 5);\n    return $dir !== '' && (is_dir($dir) || is_writable(\\dirname($dir)));\n}","tryCatchPattern":"try {\n    $storage = new FileProfilerStorage($dsn);\n} catch (\\RuntimeException $e) {\n    error_log($e->getMessage());\n    $storage = null; // disable profiling rather than failing the request\n}","preventionTips":["Provision the storage directory in deployment scripts with correct ownership before the app boots.","Use an absolute path under a guaranteed-writable location (var/cache) rather than hardcoded paths.","Validate the profiler DSN at config-load time with a small bootstrap check.","Ensure the target path is not occupied by a regular file."],"tags":["filesystem","symfony","profiler","configuration"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}