How to set Developer Mode or Production Mode in Magento 2?

To improve security and ease-of-use, Magento 2 added a command that switches Magento modes from developer to production and vice versa.

Production mode also has better performance because static view files are populated in the pub/static directory and because of code compilation.

  • In version 2.0.6 and later, Magento does not explicitly set file or directory permissions when you switch between default, develop, and production modes.
  • Unlike other Magento modes, developer and production modes are set in env.php (app/etc).

When you change to developer or production mode, Magento2 clear the contents of following directories when you change modes:

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

Exceptions:

  • .htaccess files are not removed
  • pub/static contains a file that specifies the version of static content; this file is not removed

By default, Magento uses the var directories to store the cache, logs, and compiled code. You can customize this directory but in this guide, it’s assumed to be var.

Display Magento 2 current mode

The easiest way to do that is to run this command as the Magento file system owner. If you have shared hosting, this is the user your provider gives you to log in to the server. If you have a private server, it’s typically a local user account on the Magento server.

Command usage:

magento deploy:mode:show

In fact, I run aboved command, it doesn’t work but I run followed command under Magento root folder and it’s ok.

php bin/magento deploy:mode:set developer

A message similar to the following displays:

Current application mode: developer.

Magento 2 Change modes

Command usage:

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

It’s similar with above case, if aboved command doesn’t work, you can try followed command:

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

where

{mode} is required; it can be either developer or production

--skip-compilation is an optional parameter you can use to skip code compilation when you change to production mode.

Examples follow.

Change to production mode

magento deploy:mode:set production

Like before, you also can try followed command if above command doesn’t work:

php bin/magento deploy:mode:set production

Following is a summary of messages that display:

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.

Change to developer mode

When you change from production to developer mode, you should clear generated classes and Object Manager entities like proxies to prevent unexpected errors. After doing so, you can change modes. Use the following steps:

  1. If you’re changing from production mode to developer mode, delete the contents of the var/generation and var/didirectories:
    rm -rf <your Magento install dir>/var/di/* <your Magento install dir>/var/generation/* 
    
  2. Set the mode:
    magento deploy:mode:set developer
    

    The following message displays:

    Switched to developer mode.
0 Likes
995 Views

You may also like

Leave A Comment

Please enter your name. Please enter an valid email address. Please enter message.