This article shows how you can enable or disable Maintenance mode in Magento 2 using the command line. In my previous article, I have listed out all the command line tools that can be used in Magento 2. This article specifically shows about commands to enable/disable maintenance mode in Magento 2.
Check Maintenance Mode Status
First of all, let’s get the information of the maintenance mode in Magento 2. We check whether the maintenance mode is enabled or disabled.
php bin/magento maintenance:status
Running the above command will output something like this:
Status: maintenance mode is not active
List of exempt IP-addresses: none
This shows that the maintenance mode is not enabled on the Magento site.
Enable Maintenance Mode
You can enable maintenance mode with the following command:
php bin/magento maintenance:enable
Running the above command will output something like this:
Enabled maintenance mode
Now, let’s again check the status of the maintenance mode:
php bin/magento maintenance:status
Running the above command will output something like this:
Status: maintenance mode is active
List of exempt IP-addresses: none
Enable Maintenance Mode for Specific IP Addresses
Above way of enabling maintenance mode will activate the maintenance mode for all IP addresses. No one will be able to access the frontend of the site.
But, you might have the requirement to allow the Magento site’s frontend access to particular people. For example, you might need to give access to the site to the website developer.
In such scenario, you have to set the IP address of the developer in the allowed list. That is, anyone from the allowed IP address can access the site even in the maintenance mode.
Let us enable maintenance mode and put two IP addresses (192.168.0.107 & 192.168.0.108) on the exclusion list. That means all users of the site will see the Maintenance mode page but users accessing the site from IP address 192.168.0.107 & 192.168.0.108 will see the actual site page.
php bin/magento maintenance:enable --ip=192.168.0.107 --ip=192.168.0.108
Running the above command will output something like this:
Enabled maintenance mode
Set exempt IP-addresses: 192.168.0.107, 192.168.0.108
Check Status
php bin/magento maintenance:status
Running the above command will output something like this:
Status: maintenance mode is active
List of exempt IP-addresses: 192.168.0.107, 192.168.0.108
To remove all IP addresses from the exempt list
php bin/magento maintenance:enable --ip=none
Running the above command will output something like this:
Enabled maintenance mode
Set exempt IP-addresses: none
Disable Maintenance Mode
You can disable maintenance mode with the following command:
php bin/magento maintenance:disable
Running the above command will output something like this:
Disabled maintenance mode
Hope this helps. Thanks.