{"record":{"id":"f53f131152bad0ec","repo":"OpenAPITools/openapi-generator","slug":"failed-to-cache-configuration","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/container.php","lineNumber":34,"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":16,"sourceCodeEnd":47,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/resources/php-mezzio-ph/container.php#L16-L47","documentation":"In the generated php-mezzio-ph skeleton, container.php merges the YAML config files and, when 'cache_configuration: true' is set in config.yml, writes the merged config to data/cache/config.php via ConfigFactory::toFile (CONFIG_CACHE_PATH, line 13). If that write returns false — almost always because the data/cache directory is missing or not writable by the PHP process user — a RuntimeException 'Failed to cache configuration' aborts container bootstrapping on every request.","triggerScenarios":"Freshly generated Mezzio app with cache_configuration: true where data/cache does not exist (not committed to git) or is owned by root/another user; deploying behind PHP-FPM where the www-data user cannot write the directory; read-only container filesystems.","commonSituations":"Cloning a generated project on a new machine or CI runner and hitting the cache write immediately; Docker images running as a non-root user without chown of the app dir; cache file left root-owned after running composer/console as root once.","solutions":["Create and grant write access: mkdir -p data/cache && chown -R www-data:www-data data (or chmod -R 775 data/cache) so the web/CLI user can write.","For development, set cache_configuration: false in config/config.yml to skip caching entirely.","Remove a stale, unreadable data/cache/config.php (rm data/cache/config.php) after permission changes, since a cached file is preferred once readable."],"exampleFix":"# before\n# config.yml: cache_configuration: true, but data/cache missing\nphp public/index.php\n# RuntimeException: Failed to cache configuration\n\n# after\nmkdir -p data/cache\nchown -R www-data:www-data data\ncache_configuration: true  # works now\n# or in config.yml for dev:\ncache_configuration: false","handlingStrategy":"validation","validationCode":"<?php\n// run before the container boots, e.g. in public/index.php during deploys\n$cacheDir = dirname(CONFIG_CACHE_PATH);\nif (($config['cache_configuration'] ?? false)\n    && (!is_dir($cacheDir) || !is_writable($cacheDir))) {\n    throw new RuntimeException(\n        \"data/cache is missing or not writable; run: mkdir -p $cacheDir && chown -R <php-user> \" . dirname($cacheDir)\n    );\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        // permissions problem: surface an actionable message instead of a 500\n        error_log('config cache unwritable: fix data/cache permissions or set cache_configuration: false');\n    }\n    throw $e;\n}","preventionTips":["Make the deploy pipeline create data/cache with the PHP-FPM user as owner.","Keep cache_configuration: false outside production; enable it only where the dir is provably writable.","Never run composer/console as root in the app dir — it leaves root-owned cache files."],"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"}