Magento 2 engine has 3 main modes: default, developer and production.
Developer Mode
Intended for development only, this mode:
- Symlinks to static view files are published to the pub/static directory.
- 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 Mode
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 `pub/static` only. New or updated files are not written to the file system.
You should run Magento in Production mode once it is deployed to a production server and is customer facing. Here’s why:
- Provides the highest performance.
- Errors are logged in the file system and are never displayed to the user.
- Static view file materialization is disabled.
- This means the static view files are not regenerated every time they are called, they are deployed using the command line tool and stored in the pub/static directory.
- Any changes to view files require running the deploy tool again.
- The view files are deployed using the command line tool, this means the web user does not need to have write access, and the pub/static directory can have read-only permissions which is a more secure setup.
- The Magento docroot has read-only permissions.
As said before, development mode should never be used on a live site. So, when you need to make changes, you should instead generate static content in development and then use the deployer.php tool to push changes to production.
___________
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.
- Symlinks to static view files are published to the pub/static directory.
- Exceptions are not displayed to the user; instead, exceptions are written to log files.
- Hides custom X-Magento-* HTTP request and response headers.
___________
Maintenance Mode
This is an out-of-the-box feature in Magento 2 that can be used when you want to make your site unavailable to the public during updates or other changes, a 503 is shown.
The method Bootstrap::assertMaintenance() controls this mode, and you have to create a flag file (var/.maintenance.flag) to enable the mode.
You can specify a group of people to have access to the site while this mode is employed by placing the associated IPs in var/.maintenance.ip.
Key Features Of The Magento 2 System Modes
Developer Mode | Production Mode | Default Mode | |
Static File Caching | ✓ | ||
Exceptions Displayed | ✓ | ||
Exceptions Logged | ✓ | ✓ | |
Negative Performance Impact | ✓ | ✓ |
__________
Command Line
You can switch your Magento store mode using the following command in your CLI:
- [mode] is required; it can be either developer or production
- –skip-compilation is an optional parameter that skips code compilation when you change to production mode.
__________
Web Server Environment
Apache web servers with mod_php support this method. The environment variables can be set in the main apache configuration or in the .htaccess.
If you are using an Apache system you can do the following:
- Open Apache
- Open the .htaccess file
- Use the MAGE_MODE system environment variable to specify the mode as follows:
- [mode] is required; it can be either default, developer or production
After setting the mode you will need to restart the web server for it to take effect.
____________
php-fpm Environment
You can specify the mode in the php-fpm config or in the system environment in which the php-fpm is started.
In the php-fpm config file, the value can be set as follows:
- [mode] is required; it can be either default, developer or production
__________
Displaying The Current Mode
Command Line
You can view which mode are you in by using the following command in CLI:
It will then show the following message: