Enable/Disable Maintenance Mode in Magento 2 via Command Line

Whenever you need to upload the new files or customized code on your production server, it’s very important to take your store to offline by enabling maintenance mode. Because, in maintenance mode, the temporary page will be shown to your customers until complete the work on your server and return to production mode. In Magento 2, it’s very easy to handle the maintenance mode using the command-line interface. Here is the blog which will help you to enable/disable maintenance mode in Magento 2 via the command-line interface.

Check Maintenance Mode Status:

Run the below SSH command in your Magento 2 installed root directory to check whether the maintenance mode is enabled or disabled in your Magento 2 store.

php bin/magento maintenance:status

This will return the following output,

Status: maintenance mode is not active
List of exempt IP-addresses: none

This shows that the maintenance mode is not enabled on your Magento 2 website.

Enable Maintenance Mode:

Run the below SSH command in your Magento 2 installed root directory to enable maintenance mode in your Magento 2 store.

php bin/magento maintenance:enable

This will return the following output,

Enabled maintenance mode

Enable Maintenance Mode for Specific IP Addresses:

Run the below SSH command in your Magento 2 installed root directory to enable maintenance mode for specific IP address,

php bin/magento maintenance:enable --ip=192.168.0.56 --ip=192.168.0.57

This will return the following output,

Enabled maintenance mode
Set exempt IP-addresses: 192.168.0.56, 192.168.0.57

The above command is used to enable maintenance mode and put two IP addresses (192.168.0.56 & 192.168.0.57) on the exclusion list. Which means all the users of the site will see the maintenance mode page but users accessing the website from IP address 192.168.0.56 & 192.168.0.57 will see the actual website page.

Remove IP Addresses From Exempt List:

Run the below SSH command to remove the IP address from the exempt list,

php bin/magento maintenance:enable --ip=none

This will return the following output,

Enabled maintenance mode
Set exempt IP-addresses: none

Disable Maintenance Mode:

Run the below SSH command in your Magento 2 installed root directory to disable maintenance mode in your Magento 2 store.

php bin/magento maintenance:disable

This will return the following output,

Disabled maintenance mode

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *