57
votes

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.

6

6 Answers

40
votes

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

8
votes

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>

5
votes

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!

1
votes

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
0
votes

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.

-11
votes

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.