Magento 2E-CommerceHow To GuideMay 28, 2024Simon Walker

Magento 2 Modes: Set Developer, Production & Default Mode

Magento 2 Modes: Set Developer, Production & Default Mode

Magento 2 is not just an improvement over Magento in terms of performance or security. Instead, it introduced a wide range of innovative features that have transformed the eCommerce experience. One of the major changes brought about by Magento 2 is the three different modes.

What do we mean by modes? They represent different deployment environments. Each mode offers a unique set of features. Their purpose is to provide a much-needed performance boost when performing specific tasks. In this article, we are going to share everything there is to know about Magento 2 modes.

Related Articles:

Overview Of Magento Modes

After installing Magento 2 and setting up your store, you are in the default mode. But what most Magento 2 owners don’t realise is that they can easily switch between two other modes as well. As mentioned earlier, they offer extra features. Let’s first understand what these 3 modes are before moving forward.

Three Magento 2 modes of operation are:

  • Default
  • Developer
  • Production

How To Check the Current Magento 2 Mode?

If you are a tech person, you can know the mode just by glancing over the interface. In case you are a non-tech Magento 2 store owner, here’s what you need to do to check the current mode. 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 Magento 2 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.

You may notice that your store loads quite slow in this mode. This is not a bug, nor does it indicate an issue with your store. Instead, developer mode is the slowest of the 3 modes because of the lack of caching functions. So, don’t worry if it takes longer than usual to perform the desired tasks.

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 Magento 2 Production Mode?

Production mode is built for speed and optimisation 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 Magento 2 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 work for all Magento versions (2.1.x, 2.2.x, 2.3.x, 2.4.x)

Final Thoughts

As a Magento 2 store owner, it is imperative that you understand the differences between the different Magento modes and how to switch between them. Each mode helps you carry out specific tasks seamlessly. If you do get tangled in issues that require expert help, reach out to us.