Magento 2 Modes: Set Developer, Production & Default Mode

Magento 2 Modes: Set Developer, Production & Default Mode

This guide has everything you need to know about Magento 2 Modes.

In this guide you’ll learn:
  • What are different Magento 2 modes
  • How to enable production mode from command line
  • How to enable developer mode from command line
  • How to enable default mode from command line
  • Lots more
Let’s dive right in.

Overview of Magento Modes

New Magento users are often unaware that Magento can switch between 3 different modes which optimizes its performance based on the tasks they are going to perform. We're going to discuss the difference between Magento 2 modes, what they are used for, and how to switch between them.

Three Magento 2 modes of operation are:
  • Default
  • Developer
  • Production

How to Check the Current Magento 2 Mode?

The easiest way to check Magento 2 mode is to run the following command:
  • bin/magento deploy:mode:show
It will display a message similar to this.
  • Current application mode: {mode}

Where {mode} displays the Current Mode. It can be either Developer or Production.

How to Manually Set Magento 2 Modes?

Needless to say, you would want to switch between Magento modes to carry out different tasks. You can do this via the command line applying different commands. Before you do this, make sure to connect to your Magento root directory and then apply the following command.
  • bin/magento deploy:mode:set {mode}

Where {mode} represents the mode, you want to change to developer or production mode.

What is Developer Mode?

This is the ideal mode for developing your online store. All the settings and capabilities are set to suit the development work. In Magento 2 developer mode, the majority of error messages are displayed directly on the web page, so you are immediately aware of the issue or cause without shifting to error logs. Developer mode is the slowest of the 3 modes because of the lack of caching functions.

How to Set Magento 2 Developer Mode?

To set the Magento 2 developer mode via command line, you need to delete the contents of the generated/code and generated/metadata directories:
  • rm -rf /generated/metadata/* /generated/code/*
Run the following command via CLI to set the Developer mode in Magento 2.
  • bin/magento deploy:mode:set developer

After running the above command, it will display the Enabled Developer Mode message.

How to Disable Developer Mode in Magento 2?

Disabling developer mode means you want to switch to any other mode. The following command will enable the production mode and disable the developer mode.
  • bin/magento deploy:mode:set production

What If CSS is Not Properly Loading in Magento 2 Developer Mode?

When in developer mode, you may get a 404 error for scripts and CSS preventing CSS to load. This is because Magento 2 tries to create symlinks for some static resources. You can do the following to avoid or fix this error.

  • Open up app/etc/di.xml and find the virtualType name="developerMaterialization". In that section you’ll find an item name="view_preprocessed" that needs to be modified or deleted. You can modify it by changing the contents from Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
  • Delete the files under pub/static to delete any existing symlinks. Be careful not to delete the .htaccess.

What is Production Mode?

Production mode is built for speed and optimization and is ideal if you are making your store live. In this mode, all page content is cached to decrease page load time and increase the overall system performance. Magento 2 production mode is also the most secure and the file structure is not vulnerable unlike the above two modes. Additionally, some settings can be disabled from the backend to minimize the risk of breaking or misusing something. Production mode is the hardest to debug issues because no error message is sent to the web browser.

How to Set Magento 2 Production Mode?

To set the Production Mode via command line, use the following command:
  • bin/magento deploy:mode:set production

You will see the message Enabled Production Mode. Now, your store is running in the Production mode.

What is Default Mode?

Quite obvious, the Magento 2 default mode operates when no other mode is specified. It’s a mix of both developer and production mode where it does not have the debugging capability of the developer mode and the speed of the production mode. Therefore, default mode serves no real purpose other than allowing you to quickly become familiar with Magento and load the store online. This is not the mode if you are doing development work because debugging issues take longer due to shifting between the different error log files.

Default mode also does not have the complete cashing potential unlike production mode because files are still generated on the fly.

How to Enable Default Mode in Magento 2?

To enable the Magento 2 Default Mode via command line, use the following command:
  • bin/magento deploy:mode:set default

You will see the message Enabled Default Mode.

In this article, we've briefly explained the Magento 2 modes. Now you can easily set default, developer, & production mode in your website.

The above commands works for all Magento versions (2.1.x, 2.2.x, 2.3.x, 2.4.x)

Related Articles: