Starting with symfony 2 (app_dev.php works, app.php 404's)

I followed the tutorials for symfony and hit the road block.

my installation is the current version of xampp (works on Windows), so my apache and php are relatively updated.

after their "quick tour" here:

http://symfony.com/doc/current/quick_tour/the_big_picture.html

everything worked fine in the development environment. following the instructions a bit further, I started creating my own test suite through the guide here:

http://symfony.com/doc/current/book/page_creation.html

and cannot make it work properly in a production environment. (It works fine in the Dev environment, as do the pre-installed demos.

I tried to clear the cache through the application / console cache: clear --env = prod --no-debug, however this did not help (and it seems that this is the only sentence that appears when searching.

When viewing routes, I see that the route "/ hello / {name}" appears in the list of routes.

my app / config / routing.yml has:

acme_hello: resource: "@AcmeHelloBundle/Resources/config/routing.yml" prefix: / 

as expected, and then my src / Acme / HelloBundle / Resources / config / routing.yml has

 hello: path: /hello/{name} defaults: { _controller: AcmeHelloBundle:Hello:index } 

Does anyone have any suggestions regarding the problem? (I also tried converting the demo from the box to the production route by copying the route information from the routing_dev.yml file and reassigning the package in the appkernel.php file, but that was the same problem)

--- edit ---

per request, here is my appkernel.php file

use Symfony \ Component \ HttpKernel \ Kernel; use Symfony \ Component \ Config \ Loader \ LoaderInterface;

 class AppKernel extends Kernel { public function registerBundles() { $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\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new JMS\AopBundle\JMSAopBundle(), new JMS\DiExtraBundle\JMSDiExtraBundle($this), new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(), new Acme\HelloBundle\AcmeHelloBundle(), new Acme\DemoBundle\AcmeDemoBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); } return $bundles; } public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); } } 

--- 2nd edit ---

I found a problem. I thought it was strange that nothing appeared in the prod log, so I thought that maybe something redirects me, forcing me to completely skip the app.php file.

Turns out it was a problem. I emptied the contents of the .htaccess file that was in the web folder (the one symfony was configured to), and then everything magically started working.

+4
source share
6 answers

I found a problem. I thought it was strange that nothing appeared in the prod log, so I thought that maybe something redirects me, forcing me to completely skip the app.php file.

Turns out it was a problem. I emptied the contents of the .htaccess file that was in the web folder (the one symfony was configured to), and then everything magically started working.

+1
source

I also had the same problem. I share how I solved it (Strange, but it works).

In the web / app.php change file:

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

by

 $kernel = new AppKernel('prod', true); // Enable debug mode 

Then load the page in the browser (in the application environment) and change the file again, disabling debugging:

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

Try loading the page in the browser again. It should work correctly.

Yours faithfully,

+11
source

If you are like me, just want to get an example application from a tutorial to run in Apache, then this may help you. I ran into the same issue with version 2.5 just now and finally found the answer here:

http://symfony.com/doc/current/quick_tour/the_big_picture.html

 The demo routes in our application are only available in the dev environment. Therefore, if you try to access the .../app.php/... URL, you'll get a 404 error. 

The easiest way to make it work is to use app_dev.php instead of app.php.

Just edit .htaccess and change all occurrences of app.php to app_dev.php, for example:

Line 6:

 DirectoryIndex app_dev.php 

Line 41:

 RewriteRule .? %{ENV:BASE}/app_dev.php [L] 
+6
source

Have you tried warming up your cache for the prod environment? You can do this by running the following command:

 php app/console cache:warmup --env=prod --no-debug 

You can also check your routes by running

 php app/console router:debug 

If you want to get specific route information, you can do php app/console router:debug yourRouteName . But perhaps this is what you had in mind with "viewing routes."

Another allusion to Assets . Typically, if you are moving your application from a developer to a prod environment, you should run the following commands:

 php app/console assets:install web_directory php app/console assetic:dump web_directory 

Assetic: A dump physically generates your assets, such as CSS style sheets or javascript files. Something to read about it in detail is here

Perhaps you could edit your post and publish your AppKernel.php? Maybe the beam is not activated there?

+3
source

For me, this problem was caused by the cache. After clearing the cache, the new route worked fine on prod environmment (app.php), not 404.

+1
source

I ran into the same problem. I fixed the problem by first flushing the cache from the command line using the following command:

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

After that, I deleted the cache folder from the application directory ( because I could not access my package, but only by default on the Symfony main page ), and then I updated my browser and the error disappeared.

Hope this helps.

0
source

All Articles