symfony2 - how to switch from “dev” to “prod”?

邮差的信 提交于 2019-11-27 17:23:11
egeloen

By default, Symfony 2 is delivered with a demo bundle which is just accessible from the development environment.

The production environment doesn't contain any route, so it's normal you get a 404 error page.

EDIT :

Are you sure your bundle is enable in the AppKernel.php ?

If yes, clear the cache with the following command : ./app/console cache:clear

Check if the route is enable with the following command : ./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.

As a fresh installation you normally get AppBundle under /src/AppBundle together with AcmeDemoBundle under /src/Acme/DemoBundle

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:

in /app/config/routing_dev.yml comment the following rows ( if you have them ):

_main:
    resource: routing.yml

in /app/config/routing.yml add a new route ( if you don't have )

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/


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.

Hope it helps!

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:

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

In your "web/app.php" file

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

Change the value to "true".

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

Now you can load the application in production mode.

Yuri

Your problem is related to the cache of 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

You're done.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!