Magento 2 comes pre-configured with a command that switches Magento 2 modes from developer mode to production mode. This not only facilitates the ease of use but also improves the overall security of the store as well. With this mode, we can set the ownership and file permissions appropriately. There is a small basic difference between the two modes, as explained below:

 

  • Production mode has better execution because static view files are located in the bar/static directory due to code compilation.
  • Developer mode is used for internal development on a system already secured behind the firewall. Developer mode can be of real help when you are customizing your Magento store.

Note: Developer and Production modes are set in env.php file this file locate in /app/etc/env.php

Let’s start!

Cleared Directories

When we change to Developer or Production mode, Magento system clears the contents of the following directories:

 

var/cachevar/divar/generationvar/view_preprocessedpub/static

 

  • .htaccess files are not removed

Magento 2, by default, uses the var directories to store the cache, logs, and compiled code. Magento system allows us to customize this directory.

 

  • Ownership and Permissions for Developer Mode

When you change to developer mode, Magento system clears directories only. Magento doesn’t set specific permissions on existing files. Magento system sets the following permissions on these directories and subdirectories:

Directories: 770

770 permissions, give full control to an owner and the group.

Files: 660

660 permissions, give write and read permissions to owner and the group.

Ownership and Permissions for Production Mode

When you change to Production mode, changing modes effects permissions and ownership of the following subdirectories:

 

var/view_preprocessedvar/generationvar/di

 

When you change to Production mode, Magento system set the following permissions on these directories and subdirectories:

Directories: 750

750 permissions give full control to the owner to read and execute permissions to the group.

Files: 640

640 permissions give write and read permissions to the owner and the group.

How to Display Current Mode

For the display of current mode you can use these commands:

magento deploy:mode:show

 

Message will be similar like this:

Current application mode: developer

 

Change Modes in Magento 2

To change the modes in your Magento 2, you can use this command:

magento deploy:mode:set {mode} [-s|–skip-compilation]

If you want to change to either Developer or Production mode, just replace {mode}.

–skip-compilation is an optional parameter. We can use this for skip code compilation when we change to production mode.

  • How to Change Production Mode

When we change to Production mode using this command:

magento deploy:mode:set production

Following summary is shown in Message:

Enabled maintenance mode
Requested languages: en_US
=== frontend -> Magento/luma -> en_US ===
… more …
Successful: 1884 files; errors: 0


=== frontend -> Magento/blank -> en_US ===
… more …
Successful: 1828 files; errors: 0


=== adminhtml -> Magento/backend -> en_US ===
… more …


=== Minify templates ===
… more …
Successful: 897 files modified


New version of deployed files: 1440461332
Static content deployment complete Gathering css/styles-m.less sources. Successfully processed LESS and/or SASS files CSS deployment complete Generated classes:
   Magento\Sales\Api\Data\CreditmemoCommentInterfacePersistor
   Magento\Sales\Api\Data\CreditmemoCommentInterfaceFactory
   Magento\Sales\Api\Data\CreditmemoCommentSearchResultInterfaceFactory
   Magento\Sales\Api\Data\CreditmemoComment\Repository
   Magento\Sales\Api\Data\CreditmemoItemInterfacePersistor
   … more …
Compilation complete
Disabled maintenance mode
Enabled production mode.

 

  • How to Change Developer Mode

When we change from Production mode to Developer mode, we should clear generated classes and Object Manager entities like proxies to unexpected errors. With these following steps we can change modes:

  • When we changing from Production mode to Developer mode, we need to delete the contents of the var/generation and var/di directories using this command:
rm -rf <your Magento install dir>/var/di/* <your Magento install dir>/var/generation/*

 

  • Set the mode using this command:
magento deploy:mode:set developer

 

You should be getting a message similar to this:

Switched to developer mode.

Conclusion: With this tutorial, you can easily change modes for your Magento 2 application using a command line. Leave your comments if you are stuck anywhere or want to share your suggestions with me.

Author

Why Magestore? We believe in building a meaningful & long-term relationship with you.

Write A Comment