How to Enable or Disable Maintenance Mode in Magento

The Most Popular Extension Builder for Magento 2

With a big catalog of 234+ extensions for your online store

Maintenance Mode is a useful and important mode in Magento. If you want to temporarily disable your website to test your site before it goes live, or do maintenance tasks such as updating, fixing the bug, etc., you can enable the maintenance mode.

When your website is in maintenance mode, store visitors will receive a Service Temporarily Unavailable message in their web browser instead of the frontend store. However, it is able for authorized IP addresses to access and view the store normally. We also have a post on how to enable or disable the maintenance mode in Magento 2 via command line that you can take a look at.

So, in this article, I will give you the detailed instructions to enable/ disable maintenance in both Magento 1 and Magento 2.

Enable/ disable maintenance mode in Magento:

Enable or Disable Maintenance Mode in Magento 1

To enable/ disable maintenance mode, following the below steps:

  1. Log in to your Magento administrator account via SSH
  2. Change to the directory where Magento is installed. For example, if you install Magento in the document root directory, type cd ~/public_html
  3. Open the index.php file by using your preferred text editor.
  4. Place the following line in the index.php file:

$maintenanceFile = 'maintenance.flag';

Add the following two lines after this line. where xxx.xxx.xxx.xxx is the IP address for which you want to allow access to the front-end store while Magento is in maintenance mode

$ip = $_SERVER['REMOTE_ADDR'];$allowed = array('xxx.xxx.xxx.xxx');

Note:

To exempt multiple IP addresses from the maintenance model, separate them with a comma.

For example

$allowed = array('10.1.0.127','10.1.0.252');

In case you do not know your own IP address, you can access to http://ipfinder.us/

  1. Place the following line in the index.php file:

if (file_exists($maintenanceFile)) {

Change the line to look like the following:

if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {

  1. Exit the editor after saving your changes to the index.php file.

  2. Type the following command on the command prompt:

touch maintenance.flag

After going through these above steps, you set the able status for maintenance mode. Now once you access to Magento website from an authorized IP address, the store displays normally. However, a Service Temporarily Unavailable message will be shown in the web browsers of all other visitors.

  1. To disable maintenance mode and permit all visitors to access the frontend store, type the following command:

rm maintenance.flag

Enable or Disable Maintenance Mode in Magento 2

enable or disable maintenance mode in magento 2

Firstly, let me show you how to enable/ disable the maintenance mode in Magento 2, following the below process.

Explain

Magento detects the maintenance mode as follows:

If var/.maintenance.flag does not exist, the maintenance mode is off and Magento website runs normally.

If var/.maintenance.flag exists, the maintenance mode is on.

However, the maintenance status also depends on the file var/.maintenance.ip. This file will make some exceptions so the Magento 2 maintenance mode can be off even if the var/.maintenance.flag exists.

Now, you will be instructed to enable or disable the maintenance mode by using the following commands.

Enable The Maintenance Mode in Magento 2

Command usage

php bin/magento maintenance:enable [--ip=<ip address>]

For example

php bin/magento maintenance:enable --ip=192.168.1.10 --ip=192.168.1.11

By using the above command, you will disable the maintenance mode for two IP addresses 192.168.1.10 and 192.168.1.11. The IP address of the developer who wants to debug your website is probably usually included in the above command.

Disable The Maintenance Mode in Magento 2

Command usage

php bin/magento maintenance:disable [--ip=<ip address>]

Show Maintenance Status

To know the current status of the maintenance mode, use the below command:

Command usage

php bin/magento maintenance:status

Exempt IP Addresses From Maintenance Mode

To allow access to the frontend store from a specific IP address while Magento website is in maintenance mode, type the following command:

Command usage

php bin/magento maintenance:allow-ips <ip address> .. <ip address> [--none]

For example

php bin/magento maintenance:allow-ips 192.168.1.10 192.168.1.11

Learn more: Enable or Disable maintenance mode via Command Line in Magento 2

Conclusion

The Maintenance Mode allows online stores to conduct tests and make essential adjustments by showing customers the unavailable notice instead of the usual front pages. We have shown you the shortest process to enable/ disable maintenance mode in Magento 2, and now it is your turn to do it. If you have any questions, feel free to ask us!

Our support team is enthusiastic about providing excellent Magento extensions for you with FREE Lifetime update, FREE 1-year support, risk-free 60-day money back. Let us help you quickly grow your online business!

Custom Maintenance Page with FREE extension

Looking for
Customization & Development Services?

8+ years of experiences in e-commerce & Magento has prepared us for any challenges, so that we can lead you to your success.

Get free consultant
development service

Explore Our Products:

People also searched for

Subscribe

Stay in the know

Get special offers on the latest news from Mageplaza.

Earn $10 in reward now!

Earn $10 in reward now!

comment
iphone
go up