Doctrine error: “Failed opening required '/tmp/__CG__Source.php' ”

前端 未结 3 2035
陌清茗
陌清茗 2021-01-31 08:43

I am trying to migrate my PHP application to an Ubuntu server, but without succes. Any help would be appreciated.

First I installed Doctrine successfully into /jorrit/mya

3条回答
  •  梦如初夏
    2021-01-31 09:19

    TL;DR You'll just need to generate your proxy classes manually

    vendor/bin/doctrine orm:generate-proxies
    

    Doctrine uses Proxies to connect the to database. Proxies are generated from the the Entity classes.

    In development mode, it generates a Proxies on every request because you could make changes to Entity classes.

    In production mode, it does not generate Proxies every time. For performance reason, it assumes the Proxies exist and include them directly.

    There are a few mode for Proxies generation:

    1. ALWAYS - It alwayes generates Proxies, this is the default setting for development mode
    2. NEVER - It never generates Proxies, this is the default setting for production mode
    3. ON_DEMAND - It only generates the Proxies if the Proxy files do not exist. The drawback of this option is that it has to call file_exists() every time which could potentially cause a performance issue.

    Now the command

    vendor/bin/doctrine orm:generate-proxies
    

    generates Proxy classes to /tmp. I would say this might still cause trouble because other applications on your server might delete these files unexpectedlly. One option is you can change your /tmp directory access permission to 1777

    sudo chmod 1777 /tmp
    

    The stricky bit '1' in front of 777 means that, although everyone can read/write to the /tmp directory, but you can only operate on your own files. i.e. You can't remove files created by other users.

    For further reading, please have a look at http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#auto-generating-proxy-classes-optional

    You can also set the Proxies directory to somewhere else so no other applications can modify them. http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#autoloading-proxies

提交回复
热议问题