
As you create your eCommerce store, there are multiple stages you go through: starting with development and gradually moving to live. Each stage has corresponding tasks to keep your website running.
Magento 2 handles this through the mode functionality. There are three Magento modes: default, development, and production. Each facilitates different store operations.
However, to use Magento 2 deploy modes effectively, you need to know what each is useful for. This is exactly what you will find out today: what Magento modes are, how they differ and how to switch between them.
What Are Magento 2 Deploy Modes?
Magento 2 deploy modes are modes that create specific operation conditions suitable for different store operation tasks. As we've mentioned, there are 3 core Magento deploy modes that make your experience better. Let's have a closer look at each of them.
1. Default mode
After installation, Magento 2 is in a default mode making it possible to use the platform without applying additional changes. It combines developer and production environment features but isn't entirely optimized for production.
When in default mode, Magento 2:
- dynamically generates static files (images and CSS files, etc.), then caches them. This process can slow down page loading
- does not display errors in the clipboard (on the screen) but in the log file (magento2_folder/var/log)
- works slowly
It is great to use this mode at the beginning. But then, as you develop your website, it is recommended to switch to either developer or production mode. These Magento deploy modes offer a greater set of features.
2. Developer mode
Developer mode is ideal for developers. It's useful for performing large development tasks or implementing various customizations. At the same time, it works comparatively slowly both in the admin and on the storefront.
When in developer mode, Magento 2:
- does not cache static files. They are generated and written to the Magento pub/static directory
- displays a detailed error log on the screen
- automatically compiles the code
- allows advanced code debugging
- publishes symlinks to the pub/static
- works slowly
So this Magento deploy mode is best suited for debugging and further website development.
3. Production mode
Finally, production mode is used in the live environment. It ensures the best performance out of the 3 modes and enhances the customer experience. When it's on, visitors can seamlessly interact with your content, place orders, and do it securely.
When in production mode, Magento 2:
- caches all view files for better site speed
- doesn't change image size, when generating pages
- stores all errors in the log file, and thus makes the process of debugging more difficult
- allows integrating JavaScript into a bundle
- works fast
So, this Magento deploy mode is best for the final stage — the live version of your website. In this mode, your website is ptimized in terms of performance, stability, and security.
How to Show Current Magento 2 Mode?
Now that we have established what Magento 2 deploy modes are, we also need to know how to show them.
To see what mode your Magento is in, run this simple CLI command:
php bin/magento deploy:mode:show
You'll get the following message with the corresponding Magento mode, e.g.:
Current application mode: developer
That is your current Magento 2 deploy mode.
How to Change Deploy Modes in Magento?
Except for checking which Magento mode is used, you need to know how to change it. This also takes a single CLI command.
Run the following CLI command to change the Magento 2 deploy modes:
php bin/magento deploy:mode:set {mode}
The {mode} parameter is required. You can use the following values for developer, production or default modes.
e.g. php bin/magento deploy:mode:set default
php bin/magento deploy:mode:set developer
php bin/magento deploy:mode:set production
Pro Tip: in older versions of Magento 2, you cannot return to the default mode after changing the mode. You can change the MAGE_MODE value to default in the app/etc/env.php file to return Magento 2 to the default mode if you cannot do this with the CLI command.
Avoid Downtime When Switching Between Modes
It doesn't mean that all of your development tasks are over once you switch to the Magento 2 production mode. There will always be changes to deploy which causes the downtime.
But you can easily avoid it using the zero downtime deployment commands.
They are executed in the background and don't cause downtime no matter what mode your store is in. You simply run the deployment without any interruption to the workflow. No special Magento 2 deploy mode is needed.
With all the provided details, you can manage your Magento environment effectively. Check out your Magento 2 deploy mode, change it if necessary, and ensure seamless store operation!