为什么 Lumen 环境变量过时(或不匹配?)

Why are Lumen environment variables out of date (or mismatched?)

所以出于某种原因,我的 lumen .env 变量在后端回显时与实际文件中的不匹配。

例如,APP_DEBUG 在文件中设置为 true,但是当我回显它时,我得到 false 或 null。此外,如果我尝试更改 APP_NAME 没有任何反应,它会回显一个过时的值。

我试过 运行 php artisan cache:clear 但这似乎也不起作用。对于它的价值,我在 docker 环境中 运行 这个,不确定这是否会影响事情。我也是 运行 php 7.3 和 Lumen 6.0。

您需要运行 php artisan config:clear 刷新配置文件的缓存。

命令php artisan cache:clear是刷新应用程序的缓存。

If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null.

更多信息:https://laravel.com/docs/6.x/configuration#configuration-caching

好吧,这个问题确实 docker 相关。

事实证明,我们的环境在 docker-compose.yml 文件中定义了所有与 .env 相关的属性,这些属性正在覆盖内容。所以我只需要改变这个:

environment:
  <<: *environment
  APP_NAME: <old value>
  APP_URL: http://auth.172.17.0.1.nip.io

并添加APP_DEBUG并修改APP_NAME。因此,如果其他人遇到此问题并且您正在使用 docker,请确保 docker 不会覆盖 env 属性。