簡體   English   中英

Symfony 3.0 Apache Http錯誤404和Http錯誤500響應

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

大家好,我嘗試使用Symfony 3.0在Apache2上部署示例代碼。 我做了一個示例控制器:

<?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;
  }
}

但是當我在瀏覽器上訪問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。

當我嘗試使用以下命令在計算機上進行本地測試時:

php bin/console/ server:run

Anv訪問http://127.0.0.1:8000/testhttp://127.0.0.1:8000/test2可以正常工作。

我服務器上的虛擬主機配置為:

<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>

我得到的日志是(從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)"} []

此外,通過從緩存中刪除dev文件夾,也無法解決問題。

最后,當我調試路線時,我得到:

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                     
 -------------------------- -------- -------- ------ ----------------------------------- 

您應該將app.php環境更改為生產環境。

app.php位於{root_dir} / web /下

找到線

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

並替換為

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM