Magento 2 mode: Everything you need to know ( default, developer, production)

Magento 2 platform offers default mode, Magento 2 developer mode and production mode that help to improved the performance of the platform! In this post, we’ll discuss the 3 Magento 2 modes: Default, Magento 2 developer mode and Production mode and how you can change the modes.

Overview of Magento Modes

There are three Magento 2 modes of operation that your system will be running on which are  developer, product and default mode. New users are often unaware that Magento allow switching between 3 different modes which optimizes magento performance depend on the tasks they are going to perform. Now, we’re going to explain the difference between Magento 2 modes, what they are used for, and how to change between them.

How to check the current Magento 2 mode?

Use the php bin/magento deploy:mode:show syntax as the Magento file system owner:

  • If running a shared hosting, you can apply the user given to you by the provider.
  • If running a private server, you can utilize the local user account.

After that, you will receive a message like this:

Current application mode: developer.

How  to Set Magento Modes

Magento Modes

To change or set the Magento mode, you can use the following CLI command in your SSH Terminal:

php bin/magento deploy:mode:set {mode} [-s|--skip-compilation]

In the above command, {mode} is the required field. It can be either production or developer. –skip-compilation is the optional parameter used to skip code compilation when you set the Magento 2 to production mode.

After changing the mode, you might want to clean the cache as well by running the following command:

php bin/magento cache:clean

Magento 2 mode: Everything you need to know ( default, developer, production)

1. Magento mode Default

What is Default Mode?

As the name suggest, the Default mode is how Magento 2 works, if no other mode is specified. It allows you deploy Magento on a single server without adjusting any settings and configurations. However, the Default mode is not optimized for production. When you release a Magento 2 website, this is the default mode. Also, it is the combination of developer and production mode. The Default mode comes with the following key features:

  • Errors and Exceptions are never shown to the Magento user. The users are logged to var/reports directory at the server.
  • Also, symlinks to the static view files are published to the pub/static.
  • The Default mode hides custom X-Magento-* HTTP request and response headers
  • This mode is not optimized for the production environment since the static view files are first materialized and then cached.

How to Enable Default Mode in Magento 2?

You can easily enable the Magento 2 Default Mode by running command line

  • bin/magento deploy:mode:set default

After completing, you will see the message Enabled Default Mode. The above syntax works for all Magento versions (2.1.x, 2.2.x, 2.3.x, 2.4.x)

2. Magento 2 developer mode

What is Magento 2 developer mode?

The mode is recommend for the developers  to perform all their development tasks. Though slower on the frontend and website admin, it automatically compiles code and function of advanced logging and debugging. Use this mode whenever you are customizing or extending the Magento 2’s default  features

  • Static view files are written to the Magento pub/static directory every time they’re called and are not cached.
  • Uncaught exceptions and errors are displayed in the browser
  • System logging is in verbose
  • An exception is seen in the error handler rather than being logged. It means the actual errors are seen in the browser and not just the error numbers. Hence, save yourselves from checking out them down in the file reports at the server!
  • An exception is thrown when an event subscriber cannot be invoked and leading faster debugging of module conflicts.

How to set up developer mode in Magento 2 admin panel?

How to set up developer mode in Magento 2 admin panel

There is no direct setting in the admin panel, but you can do it using certain syntax.

You need to run the php bin/magento deploy:mode:set {mode} [-s|–skip-compilation] command to turn to a mode.

*In this syntax {mode} stands for either developer or production mode;

* –skip-compilation is an optional specification used only during modes adjust for code compilation avoidance.

If you want to change or enable the production mode to developer, all the created classes and Object Manager entities should be cleared for stopping possible errors, for example, entities like proxies should be cleared before a mode switch.

Step 1. You ought to delete the var/generation and var/directories content:

rm -rf <your Magento install dir>/var/di/* <your Magento install dir>/var/generation/*

Step 2. The next step is to set the required mode:

php bin/magento deploy:mode:set developer

After completing these steps you will receive a message:

Switched to developer mode.

How to Disable Developer Mode in Magento 2?

Disabling developer mode means you want to turn to any other mode. The following syntax 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 see a 404 error for scripts and CSS preventing CSS to load. The reason for this error is due to Magento 2 tries to generate symlinks for some static resources. You can follow the below step to avoid or resolve this error.

  • Open up app/etc/di.xml and find the virtualType name=”developerMaterialization“.Here,  you need to look for an item name=”view_preprocessed” that needs to be modified or deleted. Besides, you can modify it by adjusting the contents from Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
  • After that, you need to delete the files under pub/static to remove any existing symlinks. You need to make it careful not to delete the .htaccess.

3. Magento 2 production mode

Magento 2 Production Mode

What is Production Mode?

When your Magento website is ready to go and has been deployed to a production server, you ought to set the Magento 2 in production mode. After that, you should also implement the static view files to the Magento 2 pub/static directory because this helps to enhance the performance of the website

However, debugging is comparatively hard in the production mode as the errors are logged in the file system and never displayed to the user. Also, merged CSS and Javascript do not work in this mode.

In terms of security, the production mode is the most secure since there is no symlink generated for the pub/static folder. If an unauthenticated user can access to pub/static to adjust the data, it would only be the duplicate versions of those files and overwritten during the next static deploy!

How to Set Magento 2 Production Mode?

To set the Production Mode , you can use the following command:

  • bin/magento deploy:mode:set production

You will have the message Enabled Production Mode. Now, your Magento website is running in the Production mode

Conclusion

Magento 2 supports many modes, it’s crucial  to learn how to take benefits of each mode so that you can quickly make Magento 2 work the way you want. If you have any trouble when switching Magento 2 to developer mode, CONTACT US and we will definitely support you!

Besides, if you are looking out for a cost effective Magento package for your eCommerce store, then look nowhere other than Magesolution. We not only offer an affordable Magento Development Package for all size and budget but also ensure that it helps your online business grow and sustain. Contact us for a free consultation!