php symfony2 - 如何从“开发”切换到“生产”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6789950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
symfony2 - how to switch from "dev" to "prod"?
提问by Raffael
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 egeloen
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
回答by topaz1008
Change the owner instead.sudo chown www-data:www-data -R app/cache
sudo chown www-data:www-data -R app/logs
改为更改所有者。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>
这就是让浏览器拥有文件夹。语法是:chown <USER>:<GROUP> <SWITCH> <DIRECTORY>
回答by Fabrizio Sabato
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 ( i.e. 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.ymlcomment the following rows ( if you have them ):
在/app/config/routing_dev.yml注释以下行(如果有):
_main:
resource: routing.yml
in /app/config/routing.ymladd 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.
如果第一个一切正常,您应该得到一个带有字符串“主页”的白页。(编辑这个进入 /app/Resources/views/default/index.html.twig... 这个布局是 base.html.twig ),在第二个你应该得到 Symfony2 提供的 DemoBundle。
Hope it helps!
希望能帮助到你!
回答by hackintos
I fixed it with just letting the web-server account (i.e. 'master-chef' own the /Symfony2/app/cache/prod directory. The command as below:
我通过让网络服务器帐户(即“主厨”拥有 /Symfony2/app/cache/prod 目录。命令如下:
$sudo chown master-chef -R /var/www/Symfony2/app/cache/prod
回答by hackintos
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.
现在您可以在生产模式下加载应用程序。
回答by Yuri
Your problem is related to the cache of Symfony2. I had the same problems. Try this:
你的问题与Symfony2的缓存有关。我有同样的问题。尝试这个:
sudo php app/console cache:clear --env=prod --no-debug
sudo chmod 777 -R ../sf2/
(sf2) is the main directory of my proyect
sudo php app/console cache:clear --env=prod --no-debug
sudo chmod 777 -R ../sf2/
(sf2) 是我的项目的主目录
You're done.
你完成了。