我在SO中已经解决了许多与此相关的问题,但找不到解决问题的方法。
我已经将演示符号应用程序复制到/var/www/html/myproject
文件夹中。我只能访问localhost/myproject/web/app_dev.php
,但不能访问localhost/myproject/web/app.php
。基本上我想从开发环境转换到生产环境。
当我访问app.php时,我只得到一个空白页。我该如何解决这个问题?
以下是我的routing.yml文件
app:
resource: "@AppBundle/Controller/"
type: annotation
编辑
错误日志(app/logs/prod.log)
[2015-04-06 22:54:53] request.ERROR: Uncaught PHP Exception Symfony'Component'HttpKernel'Exception'NotFoundHttpException: "No route found for "GET /"" at /home/fazlan/ppp/myproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 144 {"exception":"[object] (Symfony''Component''HttpKernel''Exception''NotFoundHttpException(code: 0): No route found for '"GET /'" at /home/fazlan/ppp/myproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php:144, Symfony''Component''Routing''Exception''ResourceNotFoundException(code: 0): at /home/fazlan/ppp/myproject/app/cache/prod/appProdUrlMatcher.php:35)"} []
您需要创建您的捆绑包并为其配置路由。之后,生产环境就可以工作了。acme可能在产品中不起作用。
@Cedric:Acme Demo捆绑包仅在app_dev.php上配置。如果您必须首先创建另一个带有正确路由的捆绑包,您可以在app/config/routing.yml中看到捆绑包的路由列表,或者您设置为配置的扩展。
点击此处了解更多信息。
在经历了不同的教程和手册之后,我终于能够通过以下更改来解决这个问题。
路由.yml
app:
resource: "@AppBundle/Controller/"
type: annotation
_acme_demo:
resource: "@AcmeDemoBundle/Resources/config/routing.yml"
AppKernel.php(此处未显示整个文件)
public function registerBundles()
{
$bundles = array(
new Symfony'Bundle'FrameworkBundle'FrameworkBundle(),
new Symfony'Bundle'SecurityBundle'SecurityBundle(),
new Symfony'Bundle'TwigBundle'TwigBundle(),
new Symfony'Bundle'MonologBundle'MonologBundle(),
new Symfony'Bundle'SwiftmailerBundle'SwiftmailerBundle(),
new Symfony'Bundle'AsseticBundle'AsseticBundle(),
new Doctrine'Bundle'DoctrineBundle'DoctrineBundle(),
new Sensio'Bundle'FrameworkExtraBundle'SensioFrameworkExtraBundle(),
new AppBundle'AppBundle(),
new Acme'DemoBundle'AcmeDemoBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony'Bundle'DebugBundle'DebugBundle();
//$bundles[] = new Acme'DemoBundle'AcmeDemoBundle();
$bundles[] = new Symfony'Bundle'WebProfilerBundle'WebProfilerBundle();
$bundles[] = new Sensio'Bundle'DistributionBundle'SensioDistributionBundle();
$bundles[] = new Sensio'Bundle'GeneratorBundle'SensioGeneratorBundle();
}
return $bundles;
}
在上述文件中注册了AcmeDemoBundle。您必须注释掉//$bundles[] = new Acme'DemoBundle'AcmeDemoBundle();
,以防止捆绑包在开发和测试环境中注册两次。
编辑完这两个文件后,转到项目文件夹并进行
php app/console --env=prod cache:clear
然后在浏览器中localhost/myproject/web/app.php
将加载与app_dev.php中相同的捆绑包