Hello大家好我尝试使用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和http://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/test和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
-------------------------- -------- -------- ------ -----------------------------------
答案 0 :(得分:3)
您应该将app.php环境更改为生产环境。
app.php位于{root_dir} / web /
下找到行
$kernel = new AppKernel('prod', false);
并将其替换为
$kernel = new AppKernel('prod', true);