Right now, our app is in the dev environment. How can we change it to prod?
Just open .env and set APP_ENV to prod!

# .env
# ...
APP_ENV=prod
# ...

Then... refresh!

This page may or may not work for you. One big difference between the dev and
prod environments is that in the prod environment, the internal Symfony cache
is not automatically rebuilt. That's because the prod environment is wired
for speed.

In practice, this means that whenever you want to switch to the prod environment...
like when deploying... you need to run a command:

./bin/console cache:clear

The bin/console file also reads the .env file, so it knows we're in the prod
environment.

And now when we refresh, it should definitely work. And check it out! There's
no web debug toolbar. And if you go to a fake page, you get a very boring error page.
And yea, you can totally customize this: just Google for "Symfony error pages":
it's really easy. The point is, this is not a big development exception page anymore.

Click back into our article, and then go find its template: show.html.twig. Let's
change the 3 hours ago to 4 hours ago:

Move back to your browser and refresh! Yep! The page did not update! That's
the behavior I was talking about.

To make it update, find your terminal and run:

./bin/console cache:clear

The dev and prod Cache Directories

Oh, and check out the var/cache directory. Each environment has its own cache
directory: dev and prod. When you run cache:clear, it basically just clears
the directory and recreates a few files. But there is another command:

./bin/console cache:warmup

This goes a step further and creates all of the cache files that Symfony will
ever need. By running this command when you deploy, the first requests will be
much faster. Heck, you can even deploy to a read-only filesystem!

And now when you refresh... it works: 4 hours ago.

Changing the Cache in the dev Environment

Change the environment back to dev:

# .env
# ...
APP_ENV=dev
# ...

Here's our next challenge. In config/packages/framework.yaml, we configured
the cache to use APCu:

What if we did want to use this for production, but in the dev environment, we
wanted to use the filesystem cache instead for simplicity. How could we do that?

We already know the answer! We just need to override this key inside the dev
environment. Create a new file in config/packages/dev called framework.yaml...
though technically, this could be called anything. We just need the same keys:
framework, cache, app. Add those, but now set app to cache.adapter.filesystem,
which was the original value:

4 lines config/packages/dev/framework.yaml

framework:

cache:

app:cache.adapter.filesystem

Let's see if it worked! Open ArticleController and dump the $cache object so
we can see what it looks like:

Leave a comment!

That web server is not meant to be used for a production environment, where you may have big numbers of users and transactions, that's why it's recommended to require it as a dev dependency, and instead you can install "Apache", "Nginx" or any other web server that fits your needs.

Cheers!

2018-05-23Raymond Dube

If the server is 'required' using --dev (composer require symfony/web-server-bundle --dev) wouldn't mean it will not work when you switch to the prod'uction environment?

I'm not sure if this is the case, but when I switch to prod, and clear the cache, the server stops unexpectedly. I would think that means I need to reuire the server bundle without the --dev.

--edit--without clearing the cache, things to seem to work correctly. Of course this is an Windows environment, so all bets are off on behaviour.

2018-05-05Dominik Drapała

Now i understand. Thank you!

2018-05-01Victor Bocharsky

Hey Dominik,

By design, dump() behaves a bit different in dev environment, it does not break your page, instead, it collects all the dumps and put them into Symfony dev toolbar. So page does not look broken. But for this some extra code is responsible, which is overhead in production, and actually, you don't have Symfony dev toolbar in production too. So if you dump something - it is showed immediately. But with die() you interrupts this dev behavior, and you see the dump immediately.

Cheers!

2018-05-01Dominik Drapała

I wonder why do i need to append dumps with die in dev environment in order to be able to see them on the web page? When i'm in dev environment dumps are printed even before doctype. When i switch back to production environment - they appears inside body section and they are visible without appending die instruction. Any clues?