magentomodecli

How To Set Magento mode Using CLI

There are few specific technicalities that you get to be aware of once you start doing developments in Magento 2. One of these things is setting your Magento store mode by using the CLI. Before we go in depth with this feature let me tell you what the basic course of action is. When you upgrade to Magento 2, it basically comes with a pre-configured command which switches Magento 2 modes to developer mode from the production mode. It not only ensures the friendly user experience but also provides complete security to your store as well. This mode also allows you to appropriately setup the file permissions and ownership settings. You should know that there is some ground differences in the two modes, such as:

– The Production mode appear to have better execution as due to the compilation of the code the static view files are located in bar/static directory.

– The Developer mode handles internal development on the system which is being secured already behind the firewall. When you are doing the customization of your Magento store then the Developer mode can appear to be of real assistance. Reminder: Both the modes (Developer and Production) are setup in the env.php file which is located in /app/etc/env.php Now let’s get started to explore how we can go about this process!

Directories Clearing

Whichever mode you opt for be it Developer or Production mode, the Magento system will clear the contents of the directories which are as followed:

var/cache var/di var/generation var/view_preprocessed pub/static

.htaccess files are not removed By default to store the chache, logs and to compile the code Magento 2 uses the var directories to store. So the Magento system gives us the authority to customize this directory.

Developer Mode – Ownership and Permissions

Now in case you switch to the developer mode then the Magento system only clears directories. Specific permissions on existing files cannot be set in Magento. While the following permissions on the mentioned directories and subdirectories are set by Magento system: Directories: 770 770 permissions, provides full control to an owner and the group. Files: 660 660 permissions, provides write and read permissions to owner and the group.

Production Mode – Ownership and Permissions

In case you switch to Production mode, the followed changes in modes effect permissions and ownership of the mentioned sub-directories:

var/view_preprocessed var/generation var/di

As you switch to Production mode, the following permissions are set by Magento system: Directories: 750 750 permissions provides full control to the owner to read and execute permissions to the group. Files: 640 640 permissions provides the write and read permissions to the owner and the group.

How to show Current Mode

To make the display of current mode, these mentioned commands can be used by you:

php bin/magento deploy:mode:shows

The Message would be will be alike this:

Current application mode: developer

Changing Modes in Magento 2

Now if you want to change the modes in your Magento 2, the following command can be used by you:

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

Changing to Production Mode

In case you desire to switch to either Developer or Production mode, all that you have to do is to just replace {mode}. An optional parameter is –skip-compilation. This we can utilize for the skip code compilation while we switch to the production mode.

By using this command when we change to Production mode:

php bin/magento deploy:mode:set production

A summary Message similar to the following is shown:

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.

Changing to Developer Mode

To change from Production mode to Developer mode, you must clear generated classes and Object Manager entities such as the proxies to unexpected errors. By following the mentioned steps, you can change the modes: – So you are changing from the Production mode to Developer mode, you require deleting the contents of the var/generation and var/di directories by using the following command:

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

– This command should be used then to select the mode:

php bin/magento deploy:mode:set developer

Finally you would get a message alike this:

Switched to developer mode

CONCLUSION

This tutorial enables you to easily change modes from your Magento application by using the CLI. If you get stuck at any point during this process feel free to ask us or you can just drop in a comment below if you wish to share your suggestions with us!

Maria Binte Saeed

Maria Binte Saeed

Technical Content Writer at Arpatech
Maria is a Technical Content Writer at Arpatech. She loves to stay up to date with the latest technological trends and working in Information Technology field. She has a keen passion for reading and blogging. You can follow her on Twitter @binte_saeed or e.mail maria.saeed[at]arpatech.com
Maria Binte Saeed

TALK TO OUR
CLOUD EXPERT

+1 (800) 214-3513
8am - 8pm UTC

Arpatechops - Managed Ecommerce Hosting Solutions
ArpatechOps bring you E-commerce
Managed Hosting and Application
Support services.

FEATURED SERVICE

Social

  • Facebook Linkdedin Twitter