【问题标题】:Symfony 3.1: error when requesting app_dev.php or app.phpSymfony 3.1:请求 app_dev.php 或 app.php 时出错
【发布时间】:2017-02-17 01:36:48
【问题描述】:

我在请求 sorial/app_dev.php 时得到这个:

Not Found

The requested URL /app_dev.php/ was not found on this server.

当请求sorial/app.php时:

注销(); $apcLoader->注册(真); */ $内核=新 AppKernel('prod', false); $kernel->loadClassCache(); //$内核=新 应用缓存($内核); // 使用HttpCache时,需要调用 前端控制器中的方法,而不是依赖于 配置参数 //Request::enableHttpMethodParameterOverride(); $请求 = 请求::createFromGlobals(); $response = $kernel->handle($request); $响应->发送(); $kernel->terminate($request, $response);

我在 Ubuntu 14.04 和 Apache 2.4 上

编辑:这是我的虚拟主机:

<VirtualHost *:80>
    ServerName sorial
    #ServerAlias sorial.es
    DocumentRoot /var/www/sorial/web
        DirectoryIndex app.php
    #SetEnv SYMFONY__DATABASE__PASSWORD jander
    <Directory /var/www/sorial/web/>
        # Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        #Order allow,deny
        #allow from all
        Require all granted
        FallbackResource /index.php
        # BEGIN EXPIRES
        <IfModule mod_expires.c>
            ExpiresActive On
            ExpiresDefault "access plus 10 days"
            ExpiresByType text/css "access plus 1 week"
            ExpiresByType text/plain "access plus 1 month"
            ExpiresByType image/gif "access plus 1 month"
            ExpiresByType image/png "access plus 1 month"
            ExpiresByType image/jpeg "access plus 1 month"
            ExpiresByType application/x-javascript "access plus 1 month"
            ExpiresByType application/javascript "access plus 1 week"
            ExpiresByType application/x-icon "access plus 1 year"
        </IfModule>
        # END EXPIRES
    </Directory>
</VirtualHost>

我的文档根在/var/www/sorial/web。

事实上,我的其他网站也有同样的问题。当我尝试使用a2dismod env 禁用/启用env_mod 时,问题就开始了,因为在添加变量SetEnv 时(正如您在我的虚拟主机中看到的那样)我得到了

apache2.service 的作业失败,因为控制进程退出 错误代码。请参阅“systemctl status apache2.service”和“journalctl -xe" 了解详情。

重启 apache 时。

【问题讨论】:

  • 您是否尝试过使用以下命令运行您的应用程序:php bin/console server:run?
  • 您能告诉我们您的 Apache VirtualHost 或 DirectoryRoot 配置吗?我想知道你为 web 目录指定了什么?
  • @Giovani 谢谢,这是可行的,但我更喜欢使用 Apache。
  • @AlvinBunk 我编辑了我的问题。
  • 为什么如果你的 VH 被命名为 sorial 你试图得到 my_site/app_dev.php 而不是 sorial/app_dev.php ?还是打错了?

标签: apache symfony


【解决方案1】:

我终于解决了我的问题,像这样安装 php5 和 libapache2-mod-php5:sudo apt-get install php5 libapache2-mod-php5

【讨论】:

    【解决方案2】:

    我终于解决了安装 php5 和 libapache2-mod-php5 的问题,如下所示:sudo apt-get install php5 libapache2-mod-php5 — @ziiweb

    您收到的错误通常是由于配置文件丢失或损坏造成的。

    apache2.service 的作业失败,因为控制进程以错误代码退出。详见“systemctl status apache2.service”和“journalctl -xe”。

    journalctl 命令can be used 可查看更多详细信息。

    $ journalctl | tail
    AH00526: Syntax error on line 5 of /etc/apache2/sites-enabled/mydomain-wsf.lan.conf
    

    您还可以进行 Apache 配置测试。

    $ apachectl configtest
    Syntax OK
    
    $ sed -i 's/SetEnv/SetEnvFoobar/' /etc/apache2/sites-enabled/test.conf
    
    $ apachectl configtest
    AH00526: Syntax error on line 12 of /etc/apache2/sites-enabled/test.conf:
    Invalid command 'SetEnvFoobar', perhaps misspelled or defined by a module not included in the server configuration
    Action 'configtest' failed.
    The Apache error log may have more information.
    

    apachectl graceful 命令也非常有用。它会重启 Apache,但会先运行一个配置测试“在启动重启以确保 Apache 不会死机之前。”

    apachectl graceful

    优雅地重新启动 Apache httpd 守护进程。如果守护程序未运行,则启动它。这与正常重启的不同之处在于当前打开的连接不会中止。副作用是旧的日志文件不会立即关闭。这意味着如果在日志轮换脚本中使用,可能需要大量延迟以确保在处理旧日志文件之前关闭它们。此命令会在启动重新启动之前自动检查 configtest 中的配置文件,以确保 Apache 不会死机。这相当于apachectl -k graceful

    ——Apache Docs

    重新安装软件可以正常工作,因为它会修复所有丢失的配置文件。

    $ apt-get install --resinstall libapache2-mod-php5 php5 
    

    另一种选择,noted here,是先清除然后安装。 非常重要的是要知道,purge 是一个破坏性命令,这意味着它将删除所有现有的配置文件。这几乎相当于全新安装。

    $ apt-get purge libapache2-mod-php5 php5
    $ apt-get install libapache2-mod-php5 php5 
    

    【讨论】:

      【解决方案3】:

      好的,我在使用 Debian 和 apache 作为服务器时遇到了同样的问题。尝试替换 web 目录中的 .htaccess 并清除缓存。

      DirectoryIndex app.php
      
      <IfModule mod_negotiation.c>
        Options -MultiViews
      </IfModule>
      
      RewriteEngine On
      RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
      RewriteRule ^(.*) - [E=BASE:%1]
      RewriteCond %{ENV:REDIRECT_STATUS} ^$
      RewriteRule ^app_dev.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 
      RewriteCond %{REQUEST_FILENAME} -f
      RewriteRule .? - [L]
      RewriteRule .? %{ENV:BASE}/app_dev.php [L] 
      

      这应该是你的虚拟主机

      <VirtualHost *:80>
       ServerName sorial
      
       DocumentRoot /var/www/sorial/web
       <Directory /var/www/sorial/web>
          AllowOverride All
          Order Allow,Deny
          Allow from All
      
       </Directory>
      
       ErrorLog /var/log/apache2/project_error.log
       CustomLog /var/log/apache2/project_access.log combined
      
      </VirtualHost>
      

      【讨论】:

        【解决方案4】:

        实际上,在我的配置中,我使用的是 .htaccess 文件,并且我看到您已经注释掉了 Options 行。不知道你有没有这样做的原因?

        如果不是,我建议取消注释:

        <Directory /var/www/sorial/web/>
            Options Indexes FollowSymLinks MultiViews
        

        看看这是否有效。

        【讨论】:

        • @Thanks,但问题仍然存在。好吧,现在请求 prod 环境时显示的文本可能不同了。我编辑了我的问题。
        猜你喜欢
        • 2013-06-15
        • 1970-01-01
        • 2013-05-17
        • 1970-01-01
        • 1970-01-01
        • 2015-09-25
        • 1970-01-01
        • 2020-03-15
        • 1970-01-01
        相关资源
        最近更新 更多