{"record":{"id":"916f56d89d8a7250","repo":"OpenAPITools/openapi-generator","slug":"failed-to-cache-configuration-916f56","errorCode":null,"errorMessage":"Failed to cache configuration","messagePattern":"Failed to cache configuration","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/resources/php-mezzio-ph-modern/container.php","lineNumber":31,"sourceCode":"$config = [];\nif (is_readable(CONFIG_CACHE_PATH)) {\n    $config = include CONFIG_CACHE_PATH;\n} else {\n    //Register extra extension for YAML files\n    ConfigFactory::registerReader('yml', 'yaml');\n\n    //Combine all configuration files in right order\n    $config = ConfigFactory::fromFiles([\n        __DIR__ . '/config/data_transfer.yml',\n        __DIR__ . '/config/path_handler.yml',\n        __DIR__ . '/config/app.yml',\n        __DIR__ . '/config.yml',\n    ]);\n\n    //Cache full configuration\n    if ($config['cache_configuration'] ?? false) {\n        if (!ConfigFactory::toFile(CONFIG_CACHE_PATH, $config)) {\n            throw new \\RuntimeException('Failed to cache configuration');\n        }\n    }\n}\n\n//Create container\n$container = new \\Laminas\\ServiceManager\\ServiceManager($config['dependencies'] ?? []);\n\n//Register full configuration as a service\n$container->setService('config', $config);\n$container->setAlias('Config', 'config');\n\nreturn $container;\n","sourceCodeStart":13,"sourceCodeEnd":44,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/resources/php-mezzio-ph-modern/container.php#L13-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["mkdir -p data/cache and make it writable by the runtime user (chown www-data / chmod 775).","Disable the cache in non-production: set cache_configuration: false in config.yml.","Delete any stale data/cache/config.php after fixing ownership so a fresh, valid cache is written."],"exampleFix":"# before\n# container boot fails: RuntimeException('Failed to cache configuration')\n\n# after (Dockerfile / deploy step)\nRUN mkdir -p data/cache \\\n && chown -R www-data:www-data data\n# or config.yml:\ncache_configuration: false","handlingStrategy":"validation","validationCode":"<?php\n$cacheDir = dirname(CONFIG_CACHE_PATH);\nif (($config['cache_configuration'] ?? false)\n    && (!is_dir($cacheDir) || !is_writable($cacheDir))) {\n    throw new RuntimeException(\"data/cache missing/unwritable: mkdir -p $cacheDir && chown -R <php-user> data\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $container = require __DIR__ . '/container.php';\n} catch (\\RuntimeException $e) {\n    if (strpos($e->getMessage(), 'Failed to cache configuration') !== false) {\n        error_log('fix data/cache permissions or disable cache_configuration');\n    }\n    throw $e;\n}","preventionTips":["Add a Dockerfile/deploy step: mkdir -p data/cache && chown -R www-data:www-data data.","Use distinct configs for dev (cache off) and prod (cache on, writable dir)."],"tags":["php","mezzio","config-cache","permissions","generated-code"],"backgroundTag":"cache-write-permission-denied","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}