【问题标题】:Symfony 4: Uncaught RuntimeException: APP_ENV environment variable is not definedSymfony 4:未捕获的 RuntimeException:未定义 APP_ENV 环境变量
【发布时间】:2018-10-10 06:03:57
【问题描述】:

我正在 docker 容器中开发一个新的 Symfony 4.0 应用程序(Apache SSL 容器正在代理 Symfony 容器)。对于开发环境来说一切都很好。在 docker 容器中,APP_ENV 设置为 prod(通过输入正在运行的 docker 容器并发出 SET 命令进行交叉检查)。我从作曲家中删除了 symfony/dotenv... 一切顺利,没有错误。

但是调用我的站点它仍然告诉我 APP_ENV 没有定义。我错过了什么?

我在这里阅读了有关将 APP_ENV 复制到“/etc/environment”中的信息。我还没有在 Symfony 文档中看到它。对此来源有任何提示吗?

谢谢,沃尔夫拉姆

【问题讨论】:

    标签: symfony environment-variables environment production-environment symfony4


    【解决方案1】:

    我想分享我找到的答案: 在 Docker 环境中,$_ENV var 用于检索环境变量。 Symfony 团队已经在 $SERVER 中实现了环境变量的检索。

    在此处记录: https://github.com/symfony/recipes/issues/331

    index.php 中的补丁(在上面的链接中提供)将暂时解决这个问题。

    沃尔夫拉姆

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,但是在 Symfony 关于将 symfony 置于 Apache 的生产模式的文档中,他们提供了以下内容:

      服务器名称域.tld ServerAlias www.domain.tld

      DocumentRoot /var/www/project/public
      <Directory /var/www/project/public>
          AllowOverride None
          Order Allow,Deny
          Allow from All
      
          <IfModule mod_rewrite.c>
              Options -MultiViews
              RewriteEngine On
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteRule ^(.*)$ index.php [QSA,L]
          </IfModule>
      </Directory>
      
      # uncomment the following lines if you install assets as symlinks
      # or run into problems when compiling LESS/Sass/CoffeeScript assets
      # <Directory /var/www/project>
      #     Options FollowSymlinks
      # </Directory>
      
      # optionally disable the RewriteEngine for the asset directories
      # which will allow apache to simply reply with a 404 when files are
      # not found instead of passing the request into the full symfony stack
      <Directory /var/www/project/public/bundles>
          <IfModule mod_rewrite.c>
              RewriteEngine Off
          </IfModule>
      </Directory>
      ErrorLog /var/log/apache2/project_error.log
      CustomLog /var/log/apache2/project_access.log combined
      
      # optionally set the value of the environment variables used in the application
      #SetEnv APP_ENV prod
      #SetEnv APP_SECRET <app-secret-id>
      #SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"
      

      注意这部分(就在上面):

      # optionally set the value of the environment variables used in the application
      #SetEnv APP_ENV prod
      #SetEnv APP_SECRET <app-secret-id>
      #SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"
      

      在此处设置您的环境变量,将工作(使用 docker)并且 Symfony 的 index.php 不需要任何 hack。

      【讨论】:

      • 嗯,这是我的第一次尝试,但我未能成功运行。你真的检查过,它有效吗?如果是这样,补丁可能已经在 Symfony 源中应用。无论如何,谢谢,Wolfram
      猜你喜欢
      • 2019-05-09
      • 1970-01-01
      • 1970-01-01
      • 2020-03-27
      • 2020-08-09
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多