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/test And http://ec2-52-48-111-226.eu-west-1.compute.amazonaws.com/test2 我得到第一个错误 500 link 和第二个错误 404。
当我尝试使用以下命令在我的机器上进行本地测试时:
php bin/console/ server:run
Anv 访问 http://127.0.0.1:8000/test and http://127.0.0.1:8000/test2 工作正常。
我服务器上的 Vhost 配置是:
<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);
大家好,我尝试使用 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/test And http://ec2-52-48-111-226.eu-west-1.compute.amazonaws.com/test2 我得到第一个错误 500 link 和第二个错误 404。
当我尝试使用以下命令在我的机器上进行本地测试时:
php bin/console/ server:run
Anv 访问 http://127.0.0.1:8000/test and http://127.0.0.1:8000/test2 工作正常。
我服务器上的 Vhost 配置是:
<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);