简体   繁体   English

Symfony 3.0 Apache Http错误404和Http错误500响应

[英]Symfony 3.0 Apache Http Error 404 And Http Error 500 response

Hello fellows I try to deploy a sample code on Apache2 using Symfony 3.0. 大家好,我尝试使用Symfony 3.0在Apache2上部署示例代码。 I have made a sample controller: 我做了一个示例控制器:

<?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

/*Request Response*/
use Symfony\Component\HttpFoundation\Response;
/*End of: "Request Response"*/

class PagesController extends Controller
{
  /**
  *@Route("/test", name="index")
  */
  public function test()
  {
    $response = new Response("Hello1");
    return $response;
  }

  /**
  *@Route("/test2", name="index2")
  */
  public function test2()
  {
    $response = new Response("Hello2");
    return $response;
  }
}

But when I visin on my browser http://ec2-52-48-111-226.eu-west-1.compute.amazonaws.com/test And http://ec2-52-48-111-226.eu-west-1.compute.amazonaws.com/test2 I get Error 500 for the first link and error 404 for the second one. 但是当我在浏览器上访问http://ec2-52-48-111-226.eu-west-1.compute.amazonaws.com/testhttp://ec2-52-48-111-226.eu -west-1.compute.amazonaws.com/test2对于第一个链接,我得到了错误500;对于第二个链接,我得到了错误404。

When I try to test it localy on my machine by using the command: 当我尝试使用以下命令在计算机上进行本地测试时:

php bin/console/ server:run

Anv visit the http://127.0.0.1:8000/test and http://127.0.0.1:8000/test2 works fine. Anv访问http://127.0.0.1:8000/testhttp://127.0.0.1:8000/test2可以正常工作。

The Vhost Configuration on my server is: 我服务器上的虚拟主机配置为:

<VirtualHost *:80 >
ServerName ec2-52-48-111-226.eu-west-1.compute.amazonaws.com
DocumentRoot /home/www/syphotest/htdocs/web

DirectoryIndex app.php

ErrorLog /home/www/syphotest/logs/error.log
CustomLog /home/www/syphotest/logs/access.log combined

<Directory /home/www/syphotest/htdocs/web>
Require all granted
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>

SetEnv OPENSHIFT_POSTGRESQL_DB_HOST localhost
SetEnv OPENSHIFT_POSTGRESQL_DB_PORT 5432
SetEnv OPENSHIFT_APP_NAME sampledb
SetEnv OPENSHIFT_POSTGRESQL_DB_USERNAME sampleuser
SetEnv OPENSHIFT_POSTGRESQL_DB_PASSWORD samplepass
</VirtualHost>

The Log I get is (from var/logs/production): 我得到的日志是(从var / logs / production):

[2016-02-16 17:08:44] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /test2"" at /home/www/syphotest/htdocs/var/cache/prod/classes.php line 2386 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET /test2\" at /home/www/syphotest/htdocs/var/cache/prod/classes.php:2386, Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0):  at /home/www/syphotest/htdocs/var/cache/prod/appProdUrlMatcher.php:71)"} []

Also by removing the dev folder from cache, did not fix the problem. 此外,通过从缓存中删除dev文件夹,也无法解决问题。

And in the end When I debug my routes I get: 最后,当我调试路线时,我得到:

sudo php bin/console debug:route
 -------------------------- -------- -------- ------ ----------------------------------- 
  Name                       Method   Scheme   Host   Path                               
 -------------------------- -------- -------- ------ ----------------------------------- 
  _wdt                       ANY      ANY      ANY    /_wdt/{token}                      
  _profiler_home             ANY      ANY      ANY    /_profiler/                        
  _profiler_search           ANY      ANY      ANY    /_profiler/search                  
  _profiler_search_bar       ANY      ANY      ANY    /_profiler/search_bar              
  _profiler_info             ANY      ANY      ANY    /_profiler/info/{about}            
  _profiler_phpinfo          ANY      ANY      ANY    /_profiler/phpinfo                 
  _profiler_search_results   ANY      ANY      ANY    /_profiler/{token}/search/results  
  _profiler                  ANY      ANY      ANY    /_profiler/{token}                 
  _profiler_router           ANY      ANY      ANY    /_profiler/{token}/router          
  _profiler_exception        ANY      ANY      ANY    /_profiler/{token}/exception       
  _profiler_exception_css    ANY      ANY      ANY    /_profiler/{token}/exception.css   
  _twig_error_test           ANY      ANY      ANY    /_error/{code}.{_format}           
  index                      ANY      ANY      ANY    /test                              
  index2                     ANY      ANY      ANY    /test2                             
  user_login                 POST     ANY      ANY    /user/login                        
  user_register              POST     ANY      ANY    /user/register                     
  user_activate              POST     ANY      ANY    /user/activate                     
 -------------------------- -------- -------- ------ ----------------------------------- 

You should change your app.php environment to production. 您应该将app.php环境更改为生产环境。

app.php is located under {root_dir}/web/ app.php位于{root_dir} / web /下

Find the line 找到线

$kernel = new AppKernel('prod', false);

and replace it with 并替换为

$kernel = new AppKernel('prod', true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM