Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Symfony2 install 404ing when I access app.php?

In Symfony2, when accessing my application locally via app_dev.php, everything works fine. However, when I access app.php it 404s:

Oops! An Error Occurred

The server returned a "404 Not Found".

Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for

like image 897
siwymilek Avatar asked Aug 09 '11 14:08

siwymilek


2 Answers

A fresh symfony 2 install does not contain any routing for the production environment. If you take a look under app/config/routing_dev.yml, you will notice that all of the routes that you see in the demo application are defined only for development. If you wish to test the demo on app.php, you have to first copy the routing from routing_dev.yml to routing.yml, and also enable the AcmeDemoBundle under you AppKernel.php:

$bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
        new Symfony\Bundle\AsseticBundle\AsseticBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
+       new Acme\DemoBundle\AcmeDemoBundle()
    }

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
-       $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
        $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    } 

(+ is the line you should add, - is the line you should remove)

like image 104
Nemanja Miljković Avatar answered Nov 10 '22 08:11

Nemanja Miljković


I had the same problem and I just cleared the cache. php app/console cache:clear --env=prod This has solved my problem.

Do not put the attribute to true: $ kernel = new AppKernel ('prod', TRUE); it will activate the debug mode and it is not recommended for the prod.

like image 16
youssman Avatar answered Nov 10 '22 07:11

youssman