简体   繁体   English

symfony2 - 如何从“dev”切换到“prod”?

[英]symfony2 - how to switch from “dev” to “prod”?

I downloaded symfony2 and I am able to run it starting from app_dev.php.我下载了 symfony2,我可以从 app_dev.php 开始运行它。

But when I start from app.php, then I get an error page 404.但是当我从 app.php 开始时,我得到一个错误页面 404。

app.php though is of course there and it gets executed. app.php 虽然当然在那里并且它被执行。

The error happens apparently somewhere after the last line of code in app.php:该错误显然发生在 app.php 中最后一行代码之后的某处:

$kernel->handle(Request::createFromGlobals())->send();

I guess there is a switch somewhere I have to configure.我想我必须配置的地方有一个开关。

EDIT :编辑

As suggested by GeLo I added the routing for the production version to app/config/routing.yml.根据 GeLo 的建议,我将生产版本的路由添加到 app/config/routing.yml。

_welcome:
    resource: "@AcmeDemoBundle/Resources/config/routing.yml"
    prefix:     /

I created src/Acme/DemoBundle/Resources/config/routing.yml with content:我创建了 src/Acme/DemoBundle/Resources/config/routing.yml 的内容:

bla:
    pattern: /
    defaults: {_controller:AcmeDemoBundle:Demo:index}

In DemoController::indexAction() I placed a die(__FILE__) ;DemoController::indexAction()我放了一个die(__FILE__) ;

nothing;没有什么; I still get 404 from app.php??我仍然从 app.php 得到 404?

EDIT regarding the answer:编辑关于答案:

./app/console --env=prod cache:clear

did the trick.成功了。 mind the env-parameter.注意 env 参数。

By default, Symfony 2 is delivered with a demo bundle which is just accessible from the development environment.默认情况下,Symfony 2 附带一个演示包,只能从开发环境中访问。

The production environment doesn't contain any route, so it's normal you get a 404 error page.生产环境不包含任何路由,所以出现 404 错误页面是正常的。

EDIT:编辑:

Are you sure your bundle is enable in the AppKernel.php?你确定你的包在 AppKernel.php 中启用了吗?

If yes, clear the cache with the following command: ./app/console cache:clear如果是,请使用以下命令清除缓存: ./app/console cache:clear

Check if the route is enable with the following command: ./app/console router:debug使用以下命令检查路由是否启用: ./app/console router:debug

Change the owner instead.而是更改所有者。
sudo chown www-data:www-data -R app/cache
sudo chown www-data:www-data -R app/logs

Thats letting the browser own the folders.那就是让浏览器拥有文件夹。 the syntax is:语法是:
chown <USER>:<GROUP> <SWITCH> <DIRECTORY>

I just wanted to integrate a couple of tips for this kind of problem since I faced it nowadays with a new fresh Symfony2 installation.我只是想为这类问题整合一些技巧,因为我现在用全新的 Symfony2 安装来面对它。

As a fresh installation you normally get AppBundle under /src/AppBundle together with AcmeDemoBundle under /src/Acme/DemoBundle作为全新安装,您通常会在 /src/AppBundle 下获得 AppBundle 以及 /src/Acme/DemoBundle 下的 AcmeDemoBundle

If you want to run AcmeDemoBundle on app_dev and, in the meanwhile, have an application ( ie AppBundle provided with fresh installation ) on app.php ( and avoid 404 ) you can also do something like that:如果你想在 app_dev 上运行 AcmeDemoBundle ,同时在 app.php 上有一个应用程序(即 AppBundle 提供全新安装)(并避免 404 ),你也可以这样做:

in /app/config/routing_dev.yml comment the following rows ( if you have them ):/app/config/routing_dev.yml中注释以下行(如果有的话):

_main:
    resource: routing.yml

in /app/config/routing.yml add a new route ( if you don't have )/app/config/routing.yml添加一个新路由(如果你没有)

index:
    pattern:  /
    defaults: { _controller: AppBundle:Default:index }

then empty cache like already advised by the others and test the application on然后像其他人已经建议的那样清空缓存并测试应用程序


1) http:// your_application_path/web/ 1) http://your_application_path/web/


2) http:// your_application_path/web/app_dev.php 2) http://your_application_path/web/app_dev.php

If everything is fine on the first one you should get a white page with a string "Homepage."如果第一个上一切正常,您应该得到一个带有字符串“主页”的白页。 ( to edit this one go in /app/Resources/views/default/index.html.twig... Layout for this one is base.html.twig ) and, on the second one you should get the DemoBundle provided by Symfony2. ( to edit this one go in /app/Resources/views/default/index.html.twig... Layout for this one is base.html.twig ) and, on the second one you should get the DemoBundle provided by Symfony2.

Hope it helps!希望能帮助到你!

I fixed it with just letting the web-server account (ie 'master-chef' own the /Symfony2/app/cache/prod directory. The command as below:我只让网络服务器帐户(即'master-chef'拥有/Symfony2/app/cache/prod目录)来修复它。命令如下:

$sudo chown master-chef -R /var/www/Symfony2/app/cache/prod

In your "web/app.php" file在您的“web/app.php”文件中

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

Change the value to "true".将值更改为“真”。

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

Now you can load the application in production mode.现在您可以在生产模式下加载应用程序。

Your problem is related to the cache of Symfony2.您的问题与 Symfony2 的缓存有关。 I had the same problems.我有同样的问题。 Try this:尝试这个:

  • sudo php app/console cache:clear --env=prod --no-debug
  • sudo chmod 777 -R../sf2/ (sf2) is the main directory of my proyect sudo chmod 777 -R../sf2/ (sf2) 是我的项目的主目录

You're done.你完成了。

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

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