{"record":{"id":"1b6f107b1f1c2d56","repo":"doctrine/orm","slug":"the-directory-s-does-not-exist-and-could-not-be","errorCode":null,"errorMessage":"The directory \"%s\" does not exist and could not be created.","messagePattern":"The directory \"(.+?)\" does not exist and could not be created\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Cache/Region/FileLockRegion.php","lineNumber":51,"sourceCode":"/**\n * Very naive concurrent region, based on file locks.\n */\nclass FileLockRegion implements ConcurrentRegion\n{\n    final public const LOCK_EXTENSION = 'lock';\n\n    /**\n     * @param numeric-string|int $lockLifetime\n     *\n     * @throws InvalidArgumentException\n     */\n    public function __construct(\n        private readonly Region $region,\n        private readonly string $directory,\n        private readonly string|int $lockLifetime,\n    ) {\n        if (! is_dir($directory) && ! @mkdir($directory, 0775, true)) {\n            throw new InvalidArgumentException(sprintf('The directory \"%s\" does not exist and could not be created.', $directory));\n        }\n\n        if (! is_writable($directory)) {\n            throw new InvalidArgumentException(sprintf('The directory \"%s\" is not writable.', $directory));\n        }\n    }\n\n    private function isLocked(CacheKey $key, Lock|null $lock = null): bool\n    {\n        $filename = $this->getLockFileName($key);\n\n        if (! is_file($filename)) {\n            return false;\n        }\n\n        $time    = $this->getLockTime($filename);\n        $content = $this->getLockContent($filename);\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Cache/Region/FileLockRegion.php#L33-L69","documentation":"InvalidArgumentException from FileLockRegion::__construct() (src/Cache/Region/FileLockRegion.php:51). The READ_WRITE cache region needs a directory for its lock files; the constructor tries to create it recursively (mkdir 0775), and that failed — the directory does not exist afterwards, so the region cannot operate.","triggerScenarios":"setFileLockRegionDirectory() points at a path whose parent is not writable by the PHP process (mkdir cannot create it), a path segment is actually a file, open_basedir restrictions exclude the path, the filesystem is read-only (containers), or the disk/inode quota is exhausted.","commonSituations":"Read-only container filesystems or missing volumes in Docker/Kubernetes; directory configured under /var/lib on a hardened server where the web-user lacks permissions; path typo (e.g. /vr/cache); safe_mode/open_basedir shared hosting restrictions.","solutions":["Pre-create the directory in deployment and grant write access to the PHP user: install -d -o www-data /var/cache/app/doctrine-lock.","Point setFileLockRegionDirectory() at a writable path the process can create (e.g. sys_get_temp_dir() . '/doctrine-slc' or the cache/ directory of the app).","Check the exact path for a typo, a same-named file in the way, open_basedir limits, and disk space/inodes.","On read-only containers, mount a writable emptyDir/volume (or tmpfs) at the configured path."],"exampleFix":"# Dockerfile / entrypoint, before: directory never created, app user cannot mkdir /var/doctrine-lock\n\n# after\nRUN mkdir -p /var/cache/doctrine-lock && chown www-data:www-data /var/cache/doctrine-lock\nENV DOCTRINE_SLC_LOCK_DIR=/var/cache/doctrine-lock","handlingStrategy":"validation","validationCode":"$dir = $lockRegionDirectory . '/' . $regionName;\nif (! is_dir($dir) && ! @mkdir($dir, 0775, true) && ! is_dir($dir)) {\n    throw new RuntimeException(\"Cannot create SLC lock dir {$dir}\");\n}\nif (! is_writable($dir)) {\n    throw new RuntimeException(\"SLC lock dir {$dir} not writable\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the lock directory in deployment (correct owner) instead of relying on runtime mkdir.","Prefer a local writable filesystem (tmp, app cache dir) for lock files — not NFS or read-only layers.","Health-check the directory in a startup probe so failures surface at boot, not first cache access."],"tags":["doctrine-orm","second-level-cache","file-locks","filesystem","permissions"],"backgroundTag":"directory-not-writable","analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}