On this page
Speed up Magento 2 by switching to production mode
Switching your Magento 2 store to production mode is often the single biggest performance gain available, and it costs nothing.
Magento 2 has three deploy modes: default, developer, and production. A surprising number of live stores are still running in default or developer mode, both of which are dramatically slower than production because Magento generates code and static files on the fly as each page is requested.
Switching to production mode is often the single biggest performance improvement available, and it costs nothing.
Check which mode your store is in
Connect via SSH, change to your Magento installation directory, and run:
php bin/magento deploy:mode:show
If the output is anything other than production, read on.
Switch to production mode
The switch rebuilds compiled code and static files. On a busy store it is worth enabling maintenance mode first so visitors are not served a broken page mid-process. The whole sequence usually takes a few minutes:
php bin/magento maintenance:enable
php bin/magento deploy:mode:set production
php bin/magento maintenance:disable
The deploy:mode:set production command automatically compiles code and deploys static content as part of the switch, so there is nothing further to run.
If compilation fails with a memory error, raise the PHP memory limit for that one command:
php -d memory_limit=2G bin/magento deploy:mode:set production
Run deploy:mode:show again afterwards to confirm the change.
What production mode actually changes
In production mode, Magento serves pre-generated static files from pub/static and pre-compiled code from generated, rather than building them on demand. Errors are written to var/log instead of being displayed in the browser. The result is a much faster time to first byte on every page, including ones not yet in cache.
Making changes while in production mode
The trade-off is that theme and layout changes are no longer picked up automatically. After installing a module, changing a theme, or editing anything that affects static assets, redeploy them:
php bin/magento setup:static-content:deploy -f en_GB
php bin/magento cache:flush
Replace en_GB with the locales your store actually uses, separated by spaces.
When to use developer mode
Developer mode displays errors on screen and skips compilation, which makes it ideal for a staging or development copy of your store. It should never be used on a live site - both for performance reasons and because it can expose error detail to visitors.
If you need any further help, please contact our support team.