OpenAPITools/openapi-generator · error · RuntimeException

Failed to cache configuration

Error message

Failed to cache configuration

What it means

Identical to the php-mezzio-ph case: the modern Mezzio skeleton's container.php merges config/data_transfer.yml, config/path_handler.yml, config/app.yml and config.yml, then — when cache_configuration is true — writes the merged array to data/cache/config.php with ConfigFactory::toFile. A false return (missing/unwritable data/cache directory, read-only FS) throws RuntimeException 'Failed to cache configuration' and every request fails during container construction.

Source

Thrown at modules/openapi-generator/src/main/resources/php-mezzio-ph-modern/container.php:31

$config = [];
if (is_readable(CONFIG_CACHE_PATH)) {
    $config = include CONFIG_CACHE_PATH;
} else {
    //Register extra extension for YAML files
    ConfigFactory::registerReader('yml', 'yaml');

    //Combine all configuration files in right order
    $config = ConfigFactory::fromFiles([
        __DIR__ . '/config/data_transfer.yml',
        __DIR__ . '/config/path_handler.yml',
        __DIR__ . '/config/app.yml',
        __DIR__ . '/config.yml',
    ]);

    //Cache full configuration
    if ($config['cache_configuration'] ?? false) {
        if (!ConfigFactory::toFile(CONFIG_CACHE_PATH, $config)) {
            throw new \RuntimeException('Failed to cache configuration');
        }
    }
}

//Create container
$container = new \Laminas\ServiceManager\ServiceManager($config['dependencies'] ?? []);

//Register full configuration as a service
$container->setService('config', $config);
$container->setAlias('Config', 'config');

return $container;

View on GitHub (pinned to fcec517be3)

Solutions

  1. mkdir -p data/cache and make it writable by the runtime user (chown www-data / chmod 775).
  2. Disable the cache in non-production: set cache_configuration: false in config.yml.
  3. Delete any stale data/cache/config.php after fixing ownership so a fresh, valid cache is written.

Example fix

# before
# container boot fails: RuntimeException('Failed to cache configuration')

# after (Dockerfile / deploy step)
RUN mkdir -p data/cache \
 && chown -R www-data:www-data data
# or config.yml:
cache_configuration: false
Defensive patterns

Strategy: validation

Validate before calling

<?php
$cacheDir = dirname(CONFIG_CACHE_PATH);
if (($config['cache_configuration'] ?? false)
    && (!is_dir($cacheDir) || !is_writable($cacheDir))) {
    throw new RuntimeException("data/cache missing/unwritable: mkdir -p $cacheDir && chown -R <php-user> data");
}

Try / catch

try {
    $container = require __DIR__ . '/container.php';
} catch (\RuntimeException $e) {
    if (strpos($e->getMessage(), 'Failed to cache configuration') !== false) {
        error_log('fix data/cache permissions or disable cache_configuration');
    }
    throw $e;
}

Prevention

When it happens

Trigger: Running the generated php-mezzio-ph-modern app with cache_configuration: true under a PHP-FPM user lacking write permission to data/cache; deploying to a container with a read-only app volume; first boot after generation where data/cache was never created.

Common situations: CI pipelines that run the app without preparing writable dirs; parity issues between dev (writable) and prod (read-only) environments; ops scripts that copy the project without preserving/creating the data directory.

Related errors


AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22). Data as JSON: /api/errors/916f56d89d8a7250. Report an issue: GitHub.