modes

As you create your store, there are multiple stages to 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 deploy mode functionality. There are three Magento modesdefault, development, and production. Each facilitates different store operations.

However, to use Magento 2 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 without downtime.

Key takeaways
  • Magento 2 offers three deploy modes — default, developer, and production.
  • Each deploy mode controls how your store behaves in different environments. This affects performance, error visibility, and all changes and updates.
  • Default mode is a transitional mode used right after installation. In this mode, Magento automatically generates static files for a convenient setup. But it's inefficient long-term, so you don't go back to it after switching to developer or production mode.
  • Developer mode is meant for active development. It offers detailed error messages, allows real-time code changes, and is ideal for cutomization and debugging — but not for live stores.
  • Production mode is required for live Magento stores. It offers the best performance, stability and speed and limits error visibility for security reasons.
  • You can check and change Magento deploy modes via CLI. This allows developers to switch environments safely when deveping, testing, or deploying static content.
  • There's always downtime when switching modes or deploying changes by default. But tools like Magefan Zero Downtime Deployment allow you to achieve zero downtime.

What Are Magento 2 Modes?

Magento 2 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.

The following table helps you quickly understand their difference.

magento modes comparison

Now, let's have a closer look at each of them.

Default mode

Magento 2 default mode is a mode activated right after installation. It makes it possible to use the platform without applying additional changes. It combines developer and production environment features, but isn't entirely optimised 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 Magento error 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. 

Developer mode

Magento 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.

Production mode

Finally, Magento production mode is used in the live environment. It ensures the best performance out of the 3 Magento 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 optimized in terms of performance, stability, and security.

How to Use Magento 2 Modes?

As you already understand, choosing the right Magento mode is not just a question of technical preference. Each mode is designed for a specific environment or purpose, and the wrong choice can impact either your store performance or security.

Since the default mode should only be used for Magento installation and initial setup, the main question is how to choose correctly between the developer and production modes.

At first sight, the tasks for these two modes in Magento seem to be clear and look like this:

choosing magento modes

Nevertheless, some of the tasks can be performed in both modes, but with different outcomes, workflows, and even risks. So here is a short overview of what each mode can offer.

Installing extensions

  • Developer mode is used for testing the extension. Magento immediately shows detailed error messages, which help developers to fix issues quickly before going live. Yet, the file paths, module structure, and server configuration may be exposed to anyone who can access the environment. And this is not safe.
  • Production mode is used for deployment, that is, for already verified extensions. In this mode, error messages are hidden in order to protect sensitive information. And as it was mentioned above, they need to be investigated through logs.

Debugging issues

  • Developer mode clearly displays (in the browser) if there are any conflicts, outdated code, PHP errors, etc., providing file paths and stack traces. Therefore, it's easy to locate and fix errors. Yet, this information can be used for hacker attacks if the environment is not well-protected.
  • Production mode relies on logs, server monitoring, and error tracking tools, which may take some time to check. However, these are the safe methods to investigate errors in the background while keeping a smooth customer experience.

Customising layouts and templates

  • Developer mode allows to change layouts and templates instantly. This way, developers can view the results of the change without the need to redeploy static content or flush caches. But disabled caches can hide template dependencies. Therefore, the real behavior may differ after deployment.
  • Production mode requires a controlled deployment process and cache flushing while implementing any change. Even though it's sometimes time-consuming, these steps ensure consistent rendering and unbroken layouts of your store. 

Working with static content (images, CSS, JS)

  • In developer mode, static content is generated immediately. This allows you to deploy static content in Magento and see the result of any change right away, omitting a lot of repetitive deployment steps. But instant generation may hide minification or merging problems, which can appear later on.
  • Production mode needs manual deployment and cache flushing after any changes to images, CSS, or JS. Otherwise, customers may still see the old versions on the storefront. 

How to Check the Current Magento Mode?

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?

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 needed values, that is, developer, production, or default modes.

Set Magento 2 production mode

To switch from the developer to production mode, log in to your server, navigate to the project root directory, and run the following CLI command: 

php bin/magento deploy:mode:set production

Set Magento 2 developer mode

To switch from production to developer mode, run the following command:

php bin/magento deploy:mode:set developer

It's recommended to delete previously generated classes and proxies before you switch the mode to avoid errors:

rm -rf generated/metadata/* generated/code/* 

Set Magento 2 default mode

To switch to the default mode, run the following command in your root:

php bin/magento deploy:mode:set default

In practice, once your Magento is up and running, there is no need to switch back to the default mode ever again. However, there could be some rare cases, like local experiments when learning Magento, for example.

Note: 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.

Switch Between Magento Modes Without Downtime

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 fixes, updates, and new features to deploy, which often results in downtime.

Fortunately, there is a solution to achieve zero downtime in Magento and keep checkout and storefront accessible while deploying updates safely on the live store.

This is possible thanks to the Magefan  Magento 2 Zero Downtime Deployment extension. So you can run the deployment without any interruptions to the workflow, or customer experinece regardless of the mode your store is in.

With all the provided details, you can now manage your Magento environment more effectively. So, check out your Magento 2 deploy mode, change it if necessary, and ensure seamless store operation with the right tools!

FAQs

Can I use developer mode on a live Magento store?
collapsible icon
No, it's not advisable since developer mode significantly reduces performance and exposes detailed error messages, which makes your store vulnerable to attacks.
Is default mode suitable for production?
collapsible icon
No. The default mode is only used for the initial Magento setup and testing.
Does changing Magento deploy mode delete store data?
collapsible icon
No. When you switch between Magento deploy modes, it doesn't affect products, customers, orders, or other store data.
Do I need to redeploy static content after switching modes?
collapsible icon
Yes. You have to redeploy static content, especially when switching to production mode.
Can developer mode be used for performance testing?
collapsible icon
No. The developer mode turns off caching and static file optimization, so your site may seem slower than it actually is in production mode.