4
votes

I have installed Symfony2, after fixing the file permissions, I can access the dev environment from my browser by pointing it to:

http://localhost/app_dev.php

However, when I try to access the production environment by pointing the browser to http://localhost, I get the following exception (from app/logs/prod.log):

[2012-08-13 11:30:03] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /" (uncaught exc eption) at /path/to/frameworks/Symfony2/app/cache/prod/classes.php line 4584 [] []

I then checked the available routes for the prod environment from the command line. here is the result of that investigation.

root@yourbox:~/path/to/frameworks/Symfony2$ php app/console router:debug -e=prod [router] Current routes Name Method Pattern

Incredibly, it shows that there are no routes defined for this environment (I didn't believe the error message - which essentially said the same thing).

So, my conclusion is this: out of the box installation of Symfony2, and the production environment has no default routes - is this true, or have I made a mistake somewhere?

More importantly, how do I fix this?. In SF1.x, it was straight forward to switch from dev to prod and vice versa. How do I view the AcmeDemo app for example, in a prod environment. ?

[[UPDATE]]

After feedback from thecatontheflat, I added a simple test route to my routing.yml file. The contents of app/config/routing.yml are now:

_welcome2:
    pattern:  /test
    defaults: { _controller: AcmeDemoBundle:Welcome:index }

When I try http://localhost/test in the browser, I get the same 404 error. When I debug the routes available at the console, I get the following output:

root@yourbox:~/path/to/frameworks/Symfony2$ php app/console router:debug -e=prod
[router] Current routes
Name      Method Pattern
_welcome2 ANY    /test
3
Possibly, you have different routes described in routing_prod.yml and routing_dev.yml. You should check that places.Vitalii Zurian
@thecatontheflat: I have no routing_prod.yml. This is not mentioned anywhere in the manual (IIRC).Homunculus Reticulli
Then, if you want to have all your routes that are defined in routing_dev to be accessible in prod environment - you have to move them to routing.yml.Vitalii Zurian
I see. That kinda makes sense (separation of prod and dev routes). I'll try that and if it works, I'll ask you to submit that as answer so I can accept it.Homunculus Reticulli
@thecatontheflat: Please see my updated question.Homunculus Reticulli

3 Answers

4
votes

I had the exact same problem!!

Symfony2 has two generic routing files called:

app/config/routing.yml and app/config/routing_dev.yml

However, it also has a bundle specific routing file in each bundle. The standard procedure is to define all of your bundle routes in your bundle routing.yml file then reference this from the main routing.yml file by adding:

YourbundlenameMainBundle:

resource: "@YourbundlenameMainBundle/Resources/config/routing.yml"

prefix:   /

This is what I had and I was still getting the error. But then I read the error more closely... no route found for GET / .... then I checked my routing_dev.yml file and of course it had a route for / from the Acme demo bundle _welcome route. This is why it works for the dev version but not the prod version!

Solution:

Add a route for / to either your routing.yml global file or your routing.yml bundle file by adding the following:

_welcome:

pattern:  /

defaults: { _controller: YourbundlenameMainBundle:Default:index }

you can change index to some other route if your welcome page is not index

1
votes

After you make sure you have your / route defined in any of your routing.yml

_welcome:
pattern:  /
defaults: { _controller: YourbundlenameMainBundle:Default:index }

clear your prod environment cache!

app/console cache:clear --env=prod
1
votes

I had the exact same problem. And it was caused because of a missing bundel in the AppKernel.php.

A little late but you might try to change this line in the web/app.php:

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

to:

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

That will enable debugging and you should be able to find your problem. When fixed you will ofcorse need to change it back to false ;).

Hope this helps.