What are the different facility we have between developer and production mode of Magento 2.x ?
Source: Magento U Fundamentals course
- Static file materialization is not enabled.
- Uncaught exceptions displayed in the browser
- Exceptions thrown in error handler, not logged
- System logging in
var/report, highly detailed.
You should use the Developer mode while you are developing customizations or extensions. The main benefit to this mode is that error messages are visible to you. It should not be used in production because of its impact on performance. In Developer mode, static view files are generated every time they are requested. They are written to the
pub/staticdirectory, but this cache is not used. This has big performance impact, but any changes a developer makes to view files are immediately visible.
Uncaught exceptions are displayed in the browser, rather than being logged. An exception is thrown whenever an event subscriber cannot be invoked.
System logging in
var/reportis highly detailed in this mode.
- Deployment phase on the production system; highest performance
- Exceptions are not displayed to the user -- written to logs only.
- This mode disables static file materialization.
- The Magento docroot can have read-only permissions.
You should run Magento in Production mode once it is deployed to a production server.
Production mode provides the highest performance in Magento 2.
The most important aspect of this mode is that errors are logged to the file system and are never displayed to the user. In this mode, static view files are not created on the fly when they are requested; instead, they have to be deployed to the
pub/staticdirectory using the command-line tool. The generated pages will contain direct links to the deployed page resources.
Any changes to view files require running the deploy tool again.
Because the view files are deployed using the CLI tool, the web user does to need to have write access. The Magento
pub/staticdirectory can have read-only permissions, which is a more secure setup on a publicly accessible server.
- Used when no other mode is specified
- Hides exceptions from the user and writes them to log files
- Static file materialization is enabled.
- Not recommended / not optimized for production: caching impacts performance negatively.
As its name implies, Default mode is how the Magento software operates if not other mode is specified.
In this mode, errros are logged to files in
var/reportsand are never shown to a user. Static view files are materialized on the fly and then cached.
In contrast to the developer mode, view file changes are not visible until the generated static view files are cleared.
Default mode is not optimized for a production environment, primarily because of the adverse performance impact of static files being materialized on the fly rather than generating and deploying them beforehand.
In other words, creating static files on the fly and caching them has a greater performance impact than generating them using the static file creation command line tool.
DEVELOPER mode features:
- PHP stack trace for exceptions is displayed in browser.
- Every XML file that Magento parses is validated against its schema file. So errors can be seen immediately.
- Static assets (images, CSS files, web fonts, JS files) are symlinked on demand to
pub/staticfolder. So that they can be recreated on the fly and accessed by web browser from
pub/staticfolder if these files were previously deleted.
- Debug HTTP headers are added to response (
- Developer configuration is visible under
Stores -> Configuration -> Advanced -> Developersection in Admin area.
- Debug logging can be enabled under
Stores -> Configuration -> Advanced -> Developer -> Debugsection.
- Static asset minification of JS and CSS files as well as JS bundling cannot be applied in developer mode. Only merging can be applied in developer mode.
PRODUCTION mode features:
Static assets are not symlinked or generated on the fly. Magento expects those files to already exist as regular files in
pub/staticfolder after running
bin/magento setup:static-content:deploycommand. If a file is missing, Magento generates 404 error. But since Magento version 2.2.4 there is a configuration setting
'static_content_on_demand_in_production' => 1that can be added to
etc/env.phpfile that allows static assets to be generated on demand in production mode.
PHP stack trace is hidden in browser. Exceptions can be found in
Errors in XML files are ignored. No exception is thrown like in developer mode just 404 error can be shown in browser.
Debug logging is always disabled in production mode.
Stores -> Configuration -> Advanced -> Developersection is hidden in Admin area in production mode. So minification or merging is not available in Admin.
Caching cannot be disabled in production mode under
System -> Cache Managementgrid in Admin area. But it can be disabled/enabled via console.