How to set Magento 2 modes (production, development)
To set a Magento 2 mode, use the following command:
1 |
magento setup:mode:set {mode} [-s|--skip-compilation] |
where
{mode} can be developer or production. It is required.
As for –skip-compilation, it is an optional parameter. You can utilize it for skipping code compilation while changing to production mode.
For changing to the production mode, use the below command:
1 |
magento setup:mode:set production |
You should get the following summary of messages as a result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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. |
While changing to the developer mode, don’t forget to clear generated classes, as well as Object Manager entities. Thus, you will prevent unexpected errors.
Changing from the production mode requires deleting the contents of the both var/generation and var/di directories:
1 |
rm -rf <your Magento install dir>/var/di/* <your Magento install dir>/var/generation/* |
To set the mode, use the following comand:
1 |
magento setup:mode:set developer |
You should get the below messadge:
1 |
Switched to developer mode. |
More tips from Magento 2 Developer’s Cookbook