Application Modes
Default, developer and production: what each mode changes about errors, static files and generated code, and how to switch.
bin/magento deploy:mode:set {developer|production} [-s|--skip-compilation]Magento runs in one of three application modes. The mode is a single value — MAGE_MODE, stored in app/etc/env.php — and it decides whether errors reach your screen, how files arrive in pub/static, and whether generated code is built while you browse.
What each mode changes
| Mode | Uncaught exception | Static view files | Generated code |
|---|---|---|---|
| default | written to a log file, not displayed | cached | built on demand |
| developer | displayed in the browser, verbose reports in var/report | written to pub/static on demand | built on demand |
| production | logged, never displayed to the user | served from the cache only, not generated | compiled before the deploy |
In production mode you also cannot enable or disable cache types from the Admin; only the command line can, and some Admin configuration fields are hidden.
Switching
bin/magento deploy:mode:show prints the current mode. bin/magento deploy:mode:set changes it, and clears var/cache, var/view_preprocessed, generated/metadata, generated/code and pub/static, keeping the .htaccess files. A switch into production mode takes minutes, because it compiles code and deploys static content.
What trips people up
A fresh install sits in default mode, which feels like developer mode until an exception vanishes into a log file. Do your work in developer mode. Coming back down from production, delete generated/metadata and generated/code before switching, or stale compiled classes survive the change. An exported MAGE_MODE variable overrides env.php, which is why deploy:mode:show adds a note about environment variables.
Example
# run every bin/magento command from the Magento root, as the file system owner
bin/magento deploy:mode:show
bin/magento deploy:mode:set developer
# these two lines are the same command: -s is the short form of --skip-compilation
bin/magento deploy:mode:set production -s
bin/magento deploy:mode:set production --skip-compilation
# Terminal output:
# Current application mode: default. (Note: Environment variables may override this value.)
# Enabled developer mode.
# Enabled production mode.
# Enabled production mode.When to use it
- Check which mode a server you have just inherited is running before changing any code.
- Get a stack trace in the browser instead of the generic error page while building a module.
- Build a staging environment into production mode and confirm the switch compiled and deployed.
- Explain why a template edit appears locally but not on a production-mode server.
More examples
Reading the mode out of env.php
deploy:mode:set writes MAGE_MODE into this file. env.php is per-environment configuration that returns an array, so it has no namespace and no strict_types declaration; it is the one PHP file in the project you read rather than write. Opening it tells you the mode and which cache types are on without running anything, which is useful on a server you have just been given access to.
<?php
// app/etc/env.php (excerpt) - generated configuration, not a class
return [
'MAGE_MODE' => 'developer',
'cache_types' => [
'config' => 1,
'layout' => 1,
'block_html' => 1,
'full_page' => 0,
],
];Coming back from production to developer
Use this when you have inherited a box that was built for production and you need to debug on it. Without the rm, Magento keeps using compiled interceptors and factories from the production build and your new code appears to be ignored. The cache flush is what makes the merged configuration reload.
# stale compiled classes survive a mode switch, so remove them first
rm -rf generated/metadata/* generated/code/*
bin/magento deploy:mode:set developer
bin/magento cache:flush
# confirm it took
bin/magento deploy:mode:showCache types in production mode
Reach for this when a production-mode site needs one cache type turned off for an investigation. The Admin controls are unavailable in that mode by design, so a colleague reporting that the checkboxes do nothing is describing expected behaviour, not a bug.
bin/magento cache:status
# in production mode this only works from the CLI; the Admin cache page cannot toggle types
bin/magento cache:disable full_page
bin/magento cache:enable full_page
Discussion