Introduction to Magento 2 modes

Display the current mode

Command usage:

magento deploy:mode:show

A message similar to the following displays:

Current application mode: developer.

Change modes

Command usage:

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

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:
    MagentoSalesApiDataCreditmemoCommentInterfacePersistor
    MagentoSalesApiDataCreditmemoCommentInterfaceFactory
    MagentoSalesApiDataCreditmemoCommentSearchResultInterfaceFactory
    MagentoSalesApiDataCreditmemoCommentRepository
    MagentoSalesApiDataCreditmemoItemInterfacePersistor
    ... 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 thevar/generation and var/di directories:
    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.

——

Developer mode

You should run the Magento software in developer mode when you’re extending or customizing it.

In developer mode:

  • Static view files are not cached; they are written to the Magento pub/static directory every time they’re called
  • Uncaught exceptions display in the browser
  • System logging in var/report is verbose
  • An exception is thrown in the error handler, rather than being logged
  • An exception is thrown when an event subscriber cannot be invoked

For more information, see Set the Magento mode.

Default mode

As its name implies, default mode is how the Magento software operates if no other mode is specified. Default mode enables you to deploy the Magento application on a single server without changing any settings. However, default mode is not optimized for production.

To deploy the Magento application on more than one server or to optimize it for production, change to one of the other modes.

In default mode:

  • Errors are logged to the file reports at server, and never shown to a user
  • Static view files are cached
  • Default mode is not optimized for a production environment, primarily because of the adverse performance impact of static files being cached rather than materialized. In other words, creating static files and caching them has a greater performance impact than generating them using the static files creation tool.

For more information, see Set the Magento mode.

Production mode

You should run the Magento software in production mode when it’s deployed to a production server. After optimizing the server environment (database, web server, and so on), you should run the static view files deployment tool to write static view files to the Magento pub/static directory.

This improves performance because static files don’t go through the fallback mechanism; instead, URLs for static files are created as needed.

In production mode:

  • Static view files are not materialized, and URLs for them are composed on the fly without going through the fallback mechanism. (Static view files are served from cache only.)
  • Errors are logged to the file system and are never displayed to the user

 

You can run Magento in any of the following modes:

Mode name Description
default Enables you to deploy the Magento application on a single server without changing any settings. However, default mode is not optimized for production.

To deploy the Magento application on more than one server or to optimize it for production, change to one of the other modes.

  • Static view file caching is enabled
  • Exceptions are not displayed to the user; instead, exceptions are written to log files.
  • Hides custom X-Magento-* HTTP request and response headers
developer Intended for development only, this mode:

  • Disables static view file caching
  • Provides verbose logging
  • Enables automatic code compilation
  • Enables enhanced debugging
  • Shows custom X-Magento-* HTTP request and response headers
  • Results in the slowest performance (because of the preceding)
production Intended for deployment on a production system. Exceptions are not displayed to the user, exceptions are written to logs only, and static view files are served from cache only. New or updated files are not written to the file system.

Leave a Comment