Symfony 4 服务器配置期间出现错误 AH00124

Posted

技术标签:

【中文标题】Symfony 4 服务器配置期间出现错误 AH00124【英文标题】:Error AH00124 during Symfony 4 server configuration 【发布时间】:2018-12-20 09:56:39 【问题描述】:

我目前正在尝试在托管 VPS 上部署我的 Symfony 4 网站,我确实非常成功地设置了所有内容,安装了 Apache2、php 7.2、mysql 服务器和 phpmyadmin。 然后我开始相应地配置我的服务器以托管一个 Symfony 4 网站,在部署我自己的应用程序之前,我尝试部署一个较小的应用程序,以便我知道至少有一部分可以与无数据库无捆绑应用程序一起使用。 当我尝试访问我的网站时没有任何反应,在 /var/log/apache2 中生成以下错误日志:

[Wed Jul 11 14:06:08.580654 2018] [core:error] [pid 13404] [client 37.97.69.85:52997] AH00124: Request exceeded the limit of 10 internal redirects due to probable
 configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Jul 11 14:06:41.901738 2018] [php7:error] [pid 13423] [client 37.97.69.85:44931] PHP Fatal error:
  Uncaught Symfony\\Component\\Dotenv\\Exception\\PathException: Unable to read the "/var/www/releases/20180710151554/public/../.env" environment file.
 in /var/www/releases/20180710151554/vendor/symfony/dotenv/Dotenv.php:54\nStack trace:\n#0 /var/www/releases/20180710151554/public/index.php(15): 
Symfony\\Component\\Dotenv\\Dotenv->load('/var/www/releas...')\n#1 main\n  thrown in /var/www/releases/20180710151554/vendor/symfony/dotenv/Dotenv.php on line 54
[Wed Jul 11 14:33:33.702774 2018] [core:error] [pid 13442] [client 37.97.69.85:53026] AH00124: Request exceeded the limit of 10 internal redirects
 due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Jul 11 14:38:07.055940 2018] [core:error] [pid 13642] [client 37.97.69.85:54628] AH00124: Request exceeded the limit of 10 internal redirects
 due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Jul 11 14:51:50.406171 2018] [php7:error] [pid 13793] [client 37.97.69.85:55651] PHP Fatal error:  Uncaught RuntimeException: 
APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file. in /var/www/demo/public/index.php:13\nStack trace:\n#0 main\n  thrown in /var/www/demo/public/index.php on line 13

我相信这来自于某处循环的网站配置文件,我在网上看到过 .htaccess 和配置文件循环的情况,但在这里我删除了 .htaccess 文件时没有任何地方。 他是我的网站配置:

<VirtualHost *:80>
    ServerName vps562960.ovh.net
    ServerAlias vps562960.ovh.net

    DocumentRoot /var/www/releases/20180710151554/public
    <Directory /var/www/releases/20180710151554>
        AllowOverride None
        Require all granted
        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/crvfakeexample.com>
    #     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/releases/20180710151554/public/bundles>
        <IfModule mod_rewrite.c>
            RewriteEngine Off
        </IfModule>
    </Directory>
    ErrorLog /var/log/apache2/vps562960.ovh.net_error.log
    CustomLog /var/log/apache2/vps562960.ovh.net_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"
</VirtualHost>

我开始对部署该网站失去希望。有没有人遇到过类似的情况,或者你们知道我做错了什么吗?

提前致谢。

【问题讨论】:

【参考方案1】:

问题很可能是 Apache 服务器没有将环境变量设置到 PHP 全局数组 $_SERVER 中。但是 symfony 试图准确地在 $_SERVER 数组中找到环境变量。要么更新 public/index.php 并将所有 $_SERVER 替换为 $_ENV 或取消注释 Apache 网站配置中的 SetEnv 指令。

【讨论】:

以上是关于Symfony 4 服务器配置期间出现错误 AH00124的主要内容,如果未能解决你的问题,请参考以下文章

Symfony 错误:“在渲染模板期间引发了异常”

Symfony 4:“Autowire:你应该明确地配置它的值。”

如何在 Symfony 4 中创建登录页面而不会出现“InvalidConfigurationException”错误?

SQL 在使用 symfony 迁移期间返回语法错误或访问冲突:1064

Leaflet:部署期间的显示问题

Symfony 4 - UniqueEntity 约束不显示消息错误