How to enable Magento maintenance mode

This article describes how to enable maintenance mode in Magento. When Magento is in maintenance mode, visitors see a Service Temporarily Unavailable message in their web browsers instead of the store. However, authorized IP addresses can still view the store normally.

This feature allows you to develop and test your store before it goes "live," or do other maintenance tasks, such as installing updates.

Enabling maintenance mode in Magento 2

To enable maintenance mode in Magento 2, follow these steps:

  1. If you have not already done so, enable the Magento command-line interface (CLI). For information about how to do this, please see this article.
  2. Log in to your account using SSH.
  3. At the command prompt, type the following command:
    cd ~/public_html
    If you installed Magento 2 in a subdirectory, change to that directory instead. For example, if you installed Magento in a subdirectory named mag2, you would type cd ~/public_html/mag2.
  4. To permit access to the front-end store from a specific IP address while Magento is in maintenance mode, type the following command. Replace xxx.xxx.xxx.xxx with the IP address for which you want to allow access:

    bin/magento maintenance:allow-ips xxx.xxx.xxx.xxx
    If you do not know your IP address, you can visit http://ipfinder.us.
  5. To enable maintenance mode, type the following command:

    bin/magento maintenance:enable

    Maintenance mode is now enabled. When you visit Magento from an authorized IP address, the store displays normally. All other site visitors, however, receive a Service Temporarily Unavailable message in their web browsers.

  6. To disable maintenance mode and re-enable the store for all visitors, type the following command:

    bin/magento maintenance:disable

    To view the maintenance mode status at any time, type the following command:

    bin/magento maintenance:status

Enabling maintenance mode in Magento 1.9 and older versions

To enable maintenance mode in Magento 1.9 and older versions, follow these steps:

  1. Log in to your account using SSH.
  2. Change to the directory where you installed Magento. For example, if Magento is in the document root directory, type cd ~/public_html.
  3. Use your preferred text editor to open the index.php file.
  4. Locate the following line in the index.php file:
    $maintenanceFile = 'maintenance.flag';

    After this line, add the following two lines. Replace xxx.xxx.xxx.xxx with the IP address for which you want to permit access to the front-end store while  Magento is in maintenance mode:

    $ip = $_SERVER['REMOTE_ADDR'];
    $allowed = array('xxx.xxx.xxx.xxx');
    • To allow multiple IP addresses, separate them with a comma. For example:
      $allowed = array('10.1.0.127', '10.1.0.252');
    • If you do not know your IP address, you can visit http://ipfinder.us.
  5. Locate 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)) {
    
  6. Save your changes to the index.php file and exit the editor.
  7. At the command prompt, type the following command:

    touch maintenance.flag

    Maintenance mode is now enabled. When you visit Magento from an authorized IP address, the store displays normally. All other site visitors, however, receive a Service Temporarily Unavailable message in their web browsers.

  8. To disable maintenance mode and re-enable the store for all visitors, type the following command:

    rm maintenance.flag

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.