php – Production rendering for Symfony 3

Question:

Hello!

I am doing a test on Symfony 3 (before that I worked with Laravel).

I just can't figure out how to configure the display of content in the prod environment. Routes through app_dev.php rendered fine, and without it a 500 error is returned.

Can you please tell me where to dig? Information on this issue on the official website has not yet been found, and the deadlines are tight.

The log contains the following:

[2016-04-18 09:13:08] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /address"" at D:\webdev\symfony\site.lc\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php line 123 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET /address\" at D:\\webdev\\symfony\\site.lc\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\EventListener\\RouterListener.php:123, Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0):  at D:\\webdev\\symfony\\site.lc\\var\\cache\\prod\\appProdUrlMatcher.php:46)"} []

Answer:

So, it's all about the cache.

Since the prod environment is optimized for speed, configuration, routing and Twig templates are compiled into bare PHP classes and cached. If you changed something in the dev environment and want to see how it looks in the prod environment, then you need to clear the cache of this environment ( prod ); if you don't, you will see what was compiled and cached earlier.

You can clear the cache in Symfony using the console:

php bin/console cache:clear

The command above will clear the cache of the dev environment, since by default console commands are executed in it ( dev environment)

To clear the cache for prod or another environment, add the appropriate option:

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

Alternative option:

php bin/console cache:clear -e prod

Источники:

Scroll to Top