doctrine/orm · error · InvalidArgumentException
The directory "%s" does not exist and could not be created.
Error message
The directory "%s" does not exist and could not be created.
What it means
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.
Source
Thrown at src/Cache/Region/FileLockRegion.php:51
/**
* Very naive concurrent region, based on file locks.
*/
class FileLockRegion implements ConcurrentRegion
{
final public const LOCK_EXTENSION = 'lock';
/**
* @param numeric-string|int $lockLifetime
*
* @throws InvalidArgumentException
*/
public function __construct(
private readonly Region $region,
private readonly string $directory,
private readonly string|int $lockLifetime,
) {
if (! is_dir($directory) && ! @mkdir($directory, 0775, true)) {
throw new InvalidArgumentException(sprintf('The directory "%s" does not exist and could not be created.', $directory));
}
if (! is_writable($directory)) {
throw new InvalidArgumentException(sprintf('The directory "%s" is not writable.', $directory));
}
}
private function isLocked(CacheKey $key, Lock|null $lock = null): bool
{
$filename = $this->getLockFileName($key);
if (! is_file($filename)) {
return false;
}
$time = $this->getLockTime($filename);
$content = $this->getLockContent($filename);
View on GitHub (pinned to d9b9ff7301)
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.
Example fix
# Dockerfile / entrypoint, before: directory never created, app user cannot mkdir /var/doctrine-lock # after RUN mkdir -p /var/cache/doctrine-lock && chown www-data:www-data /var/cache/doctrine-lock ENV DOCTRINE_SLC_LOCK_DIR=/var/cache/doctrine-lock
Defensive patterns
Strategy: validation
Validate before calling
$dir = $lockRegionDirectory . '/' . $regionName;
if (! is_dir($dir) && ! @mkdir($dir, 0775, true) && ! is_dir($dir)) {
throw new RuntimeException("Cannot create SLC lock dir {$dir}");
}
if (! is_writable($dir)) {
throw new RuntimeException("SLC lock dir {$dir} not writable");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The directory "%s" is not writable.
- Proxies destination directory '<info>%s</info>' does not hav
- Unable to use access strategy type of [%s] without a Concurr
- Unrecognized access strategy type [%s]
- If you want to use a "READ_WRITE" cache an implementation of
AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21).
Data as JSON: /api/errors/1b6f107b1f1c2d56.
Report an issue: GitHub.