Magento 2 Maintenance Mode

- Fire development, Magento 2

How to Enable / Disable Maintenance Mode in Magento 2

Maintenance mode is a crucial part of every site launch; besides, there are tons of other situations when you can use it. Being an essential part of Magento 1.x development, maintenance mode is also available in Magento 2. Below, I will tell you how to enable it in a case of new platform.

Everything about Magento 2 on Firebear

Prerequisites

First of all, you have to be logged in to the Magento server as a user with permissions to write to the file system (a web server user for example).

For running Magento commands from any directory, add the below command to  your system PATH.

Since various shells offer different syntax, follow this link to get more information about your use case. Bash shell for CentOS has the following form:

Other ways to run commands:

Use cd <your Magento install dir>/bin and run them as ./magento <command name>

Or php <your Magento install dir>/bin/magento <command name>

Please note that <your Magento install dir> is a subdirectory of your web server’s dockroot.

Check additional common arguments here.

How to enable or disable maintenance mode in Magento 2

The system detects maintenance mode as follows:

  • Magento operates normally (the mode is off), if var/.maintenance.flag does not exist.
  • If there is  var/.maintenance.flag, Magento 2 maintenance mode is on. The only exception is related to  var/.maintenance.ip. Since it can contain a list of IP addresses, a restriction occurs when an entry point is accessed via HTTP and the client IP address corresponds to an entry from the list. Thus, Magento 2 maintenance mode is off even if there is  var/.maintenance.flag.

The following commands are associated with Magento 2 maintenance mode:

where

  • –ip=<ip address> is used for exempting an IP address from maintenance mode. It can be a developer who performs the maintenance. You can easily exempt several IP addresses with the help of one command by using the option multiple times. If you use –ip=<ip address> with magento maintenance:disable , the list of IPs will be saved for later use. Use magento maintenance:enable –ip=none to clear the list of exempt IPs.
  • As for magento maintenance:status, it is used to display the maintenance mode current status.

If Magento 2 maintenance mode without IP address exemptions is required, use the following command:

To enable it for all youe clients except 192.0.3.15 and 192.0.3.16:

Maintain the list of exempt IP addresses in Magento 2

There is the [–ip=<ip list>] option for maintaining the list of exempt IP addresses in Magento 2. You should use it with the above commands.  Additionally, you can utilize the following command:

where

  • <ip address> .. <ip address> is an optional list of IP addresses to exempt. Use spaces to delimit these addresses.
  • Use –none to clear the list.

Now, you know how to work with Maintenance Mode in Magento 2. For further information examine the official source related to the usage of the mode.