服务器错误500“您的hydrator目录必须是可写的”当通过API平台和doctrine从symfony 6应用程序检索数据时

inkz8wg9  于 2023-02-23  发布在  其他
关注(0)|答案(1)|浏览(105)

当从Docker(v20.10.22)中的ubuntu示例(5.15.0 - 60-generic)向Symfony(v6.1.12,php8.2.1)应用程序正在运行的api平台接口发送请求时,类似于以下情况:
网址://本地主机/应用程序接口/帖子?限制= 20
我不断检索服务器错误500和错误消息指出"您的水合器目录必须是可写的"。
我在运行Ubuntu 22.04.1 LTS的docker容器中收到针对api平台的每个请求时都会收到此错误消息。
如果我在一个MACOS环境中运行完全相同的Docker容器设置,我不会收到这个错误消息,并且一切正常。
因此,我假设发生此错误是因为doctrine试图将查询结果缓存到Docker容器内的一个目录中,而该目录是不允许写入的。
我已经检查了var/cache的文件权限,并对它们进行了0777ed,但没有成功。
有人可以帮助我指定在水合过程中doctrine物理缓存结果的位置,这样我就可以手动启用对该目录的写访问,或者建议另一种解决方案,为docker容器中运行的doctrine启用写权限。
为了获得更好的再现性,我将composer依赖项的内容转储到这里:

composer show | grep -e "symfony\|Doctrine" 
doctrine/cache                       2.2.0     PHP Doctrine Cache library is a popular cache implementation that supports many different drivers suc...
doctrine/collections                 1.8.0     PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                      3.4.3     PHP Doctrine Common project is a library that provides additional functionality that other Doctrine p...
doctrine/data-fixtures               1.6.3     Data Fixtures for all Doctrine Object Managers
doctrine/doctrine-bundle             2.8.3     Symfony DoctrineBundle
doctrine/doctrine-fixtures-bundle    3.4.2     Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle  3.2.2     Symfony DoctrineMigrationsBundle
doctrine/event-manager               1.2.0     The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Do...
doctrine/inflector                   2.0.6     PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/...
doctrine/lexer                       2.1.0     PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                  3.6.0     PHP Doctrine Migrations project offer additional functionality on top of the database abstraction lay...
doctrine/mongodb-odm                 2.4.3     PHP Doctrine MongoDB Object Document Mapper (ODM) provides transparent persistence for PHP objects to...
doctrine/mongodb-odm-bundle          4.5.2     Symfony Doctrine MongoDB Bundle
doctrine/persistence                 3.1.4     The Doctrine Persistence project is a set of shared interfaces and functionality that the different D...
friendsofsymfony/elastica-bundle     v6.2.0    Elasticsearch PHP integration for your Symfony project using Elastica
gedmo/doctrine-extensions            v3.11.1   Doctrine behavioral extensions
symfony/apache-pack                  v1.0.1    A pack for Apache support in Symfony
symfony/asset                        v5.4.19   Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and ima...
symfony/browser-kit                  v6.2.5    Simulates the behavior of a web browser, allowing you to make requests, click on links and submit for...
symfony/cache                        v6.2.5    Provides extended PSR-6, PSR-16 (and tags) implementations
symfony/cache-contracts              v3.2.0    Generic abstractions related to caching
symfony/config                       v6.2.5    Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console                      v6.2.5    Eases the creation of beautiful and testable command line interfaces
symfony/css-selector                 v6.2.5    Converts CSS selectors to XPath expressions
symfony/dependency-injection         v6.1.12   Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts        v3.2.0    A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge              v5.4.19   Provides integration for Doctrine with various Symfony components
symfony/doctrine-messenger           v6.2.5    Symfony Doctrine Messenger Bridge
symfony/dom-crawler                  v6.2.5    Eases DOM navigation for HTML and XML documents
symfony/dotenv                       v6.2.5    Registers environment variables from a .env file
symfony/error-handler                v6.2.5    Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher             v6.2.5    Provides tools that allow your application components to communicate with each other by dispatching e...
symfony/event-dispatcher-contracts   v3.2.0    Generic abstractions related to dispatching event
symfony/expression-language          v5.4.19   Provides an engine that can compile and evaluate expressions
symfony/filesystem                   v6.2.5    Provides basic utilities for the filesystem
symfony/finder                       v6.2.5    Finds files and directories via an intuitive fluent interface
symfony/flex                         v2.2.5    Composer plugin for Symfony
symfony/framework-bundle             v6.0.19   Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-client                  v6.2.6    Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts        v3.2.0    Generic abstractions related to HTTP clients
symfony/http-foundation              v6.2.6    Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                  v6.1.12   Provides a structured process for converting a Request into a Response
symfony/mailer                       v6.1.11   Helps sending emails
symfony/maker-bundle                 v1.48.0   Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can f...
symfony/messenger                    v6.2.5    Helps applications send and receive messages to/from other applications or via message queues
symfony/mime                         v6.1.11   Allows manipulating MIME messages
symfony/monolog-bridge               v5.4.19   Provides integration for Monolog with various Symfony components
symfony/monolog-bundle               v3.8.0    Symfony MonologBundle
symfony/options-resolver             v6.2.5    Provides an improved replacement for the array_replace PHP function
symfony/password-hasher              v6.2.5    Provides password hashing utilities
symfony/phpunit-bridge               v6.2.5    Provides utilities for PHPUnit, especially user deprecation notices management
symfony/polyfill-intl-grapheme       v1.27.0   Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn            v1.27.0   Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer     v1.27.0   Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring            v1.27.0   Symfony polyfill for the Mbstring extension
symfony/polyfill-php72               v1.27.0   Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73               v1.27.0   Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80               v1.27.0   Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81               v1.27.0   Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/property-access              v5.4.19   Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info                v5.4.19   Extracts information about PHP class' properties using metadata of popular sources
symfony/proxy-manager-bridge         v5.4.19   Provides integration for ProxyManager with various Symfony components
symfony/routing                      v6.2.5    Maps an HTTP request to a set of configuration variables
symfony/security                     2.0.6     Symfony Security Component
symfony/security-bundle              v5.4.20   Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core                v5.4.19   Symfony Security Component - Core Library
symfony/security-csrf                v6.2.5    Symfony Security Component - CSRF Library
symfony/security-guard               v5.4.19   Symfony Security Component - Guard
symfony/security-http                v5.4.20   Symfony Security Component - HTTP Integration
symfony/serializer                   v5.4.19   Handles serializing and deserializing data structures, including object graphs, into array structures...
symfony/service-contracts            v2.5.2    Generic abstractions related to writing services
symfony/stopwatch                    v6.2.5    Provides a way to profile code
symfony/string                       v6.2.5    Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clust...
symfony/translation-contracts        v3.2.0    Generic abstractions related to translation
symfony/twig-bridge                  v6.1.11   Provides integration for Twig with various Symfony components
symfony/twig-bundle                  v5.4.19   Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator                    v5.4.19   Provides tools to validate values
symfony/var-dumper                   v6.2.5    Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter                 v6.2.5    Allows exporting any serializable PHP data structure to plain PHP code
symfony/web-link                     v6.2.5    Manages links between resources
symfony/webpack-encore-bundle        v1.16.1   Integration with your Symfony app & Webpack Encore!
symfony/yaml                         v6.2.5    Loads and dumps YAML files
u3r8eeie

u3r8eeie1#

通过使用简单的umask(0000),如下所示:https://symfony.com/doc/current/setup/file_permissions.html#3-without-using-acl,此问题可以得到解决。
为什么只有在ubuntu环境下运行的docker容器才需要这个修复程序,这个问题仍然没有答案,我认为容器的行为是100%相同的,不管它们是从什么操作系统启动的,但是情况似乎并不总是这样。

相关问题