Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 - how to switch from "dev" to "prod"?

Tags:

php

symfony

I downloaded symfony2 and I am able to run it starting from app_dev.php.

But when I start from app.php, then I get an error page 404.

app.php though is of course there and it gets executed.

The error happens apparently somewhere after the last line of code in 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.

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

I created src/Acme/DemoBundle/Resources/config/routing.yml with content:

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

In DemoController::indexAction() I placed a die(__FILE__);

nothing; I still get 404 from app.php !?

EDIT regarding the answer:

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

did the trick. mind the env-parameter.

like image 376
Raffael Avatar asked Jul 22 '11 12:07

Raffael


4 Answers

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

like image 50
egeloen Avatar answered Oct 13 '22 15:10

egeloen


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>

like image 24
topaz1008 Avatar answered Oct 13 '22 15:10

topaz1008


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!

like image 5
Fabrizio Sabato Avatar answered Oct 13 '22 17:10

Fabrizio Sabato


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
like image 1
hackintos Avatar answered Oct 13 '22 15:10

hackintos