Magento has three modes: default, developer and production. Developer mode is meant for a programmer’s own machine. Live stores are surprisingly often left in it after launch.
Why it is a problem on a live store
- Slow pages: static files are generated on demand and code is checked for changes on every request.
- Exposed errors: error details, file paths and stack traces are shown to visitors, which also helps attackers.
Default mode is not much better for a live store. Production is the right mode.
Check the current mode
bin/magento deploy:mode:show
Switch to production
Do this at a quiet time. It compiles code and deploys static files, which can take several minutes. Styling may look broken briefly while it runs.
bin/magento maintenance:enable
bin/magento deploy:mode:set production
bin/magento cache:flush
bin/magento maintenance:disable
If your store uses several languages, make sure static content is deployed for all of them, for example bin/magento setup:static-content:deploy en_US ar_SA.
After switching
- Run these commands as the user that owns the files, not root, or file permissions will break.
- If you use PHP-FPM with OPcache, reload it so the new compiled code is used:
sudo systemctl reload php8.2-fpm. - From now on, every code or theme change needs
setup:di:compileandsetup:static-content:deployto take effect.
If the mode switches back
If deploy:mode:show reports developer mode again later, a MAGE_MODE environment variable is probably set in your web server, PHP-FPM pool or container config. It overrides app/etc/env.php. Remove it there.
Catch it automatically
MageMonitor checks for this every few minutes as part of its Magento health checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.
