Magento maintenance mode: How to enable/disable and improve it in your Magento website

Magento maintenance mode

Magento maintenance mode is a helpful and crucial mode in Magento 2. If you want to provisionally disable your Magento store to test your website before it goes live, or make maintenance tasks including updating, fixing the bug, etc., you can enable the maintenance mode. When your online store is in maintenance mode, users will get a Service Temporarily Unavailable message in their web browser instead of the frontend store. However, it is possible for access from authorized IP addresses to view the store normally.

What Is Magento 2 Maintenance Mode?

Magento maintenance mode lies among one of the 4 basic modes of Magento, including default, developer, production, and maintenance. Your Magento 2 website’ operation is based on these 4 modes. The table shows details:

Default: This mode enable to deploy the Magento application on a single server without any setting adjustment. However, if you want to optimize production or set up applications on multiple servers, you need to consider using a different mode instead of the default

Developer: For development only.

Production: Be suitable for Magento deployment on a production server

Maintenance:  To prevent access to the Magento Commerce website that is in the process of being upgraded or restructured.

  • Redirects site users to a default Service Temporarily Unavailable page.
  • Under maintenance mode, the var/ directory includes the .maintenance.flag file.
  • You can enable the Magento 2 maintenance mode to allow specific IP.

Magento maintenance mode is helpful  when you intend to develop and test your store before it goes “live,” or do other maintenance tasks, such as installing updates without being noticed by users. In other ways, if you enable this mode, your site will be temporarily offline and take users to a default Service Temporarily Unavailable page.

Normally, you can customize your Magento 2 website without having to put it in Magento maintenance mode. Some minor changes such as publishing new content, updating themes and plugins can still take place while not causing the website death. However, some works take you a long time to complete. For instance, when you manually configure a new theme or a new extension to adjust the behavior on your  site

If your site has a lot of traffic, you do not want your users (your potential customers) to see a broken website. This will lead to a negative impression on your business and negatively affect the customer experience. That is the reason why this function was born.

How to improve Magento maintenance mode?

Magento maintenance mode allows you to restrict visitors access to your website while making site maintenance. Unfortunately, it also freezes you out of the website. Incuding the following code to your index.php file to help you to work on your online stote while everyone else sees maintenance mode

Method

Open index.php. Above line 64 and add the below command and include the IPs to retain access to the site in the “allowed” array:

ip = $_SERVER[’REMOTE_ADDR’];
allowed = array(’1.1.1.1’,’2.2.2.2’);

Locate and adjust the line:

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

Save the file.

Cloudflare method

If using Cloudflare, add the below command to you index.php file instead:

ip = $_SERVER[’HTTP_CF_CONNECTING_IP’];
allowed = array(’1.1.1.1’,’2.2.2.2’);

Enable or Disable Maintenance Mode in Magento 2

To enable/ disable tMagento maintenance mode, you need to follow the below process.

Explain

Magento 2 detects the maintenance mode as follows:

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

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

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

By using the following commands, you can enable and disable the maintenance Mode in Magento 2

1. Enable Magento maintenance mode

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

Following the above command, you will disable the maintenance mode for 2 IP address 192.168.1.10 and 192.168.1.11. The IP address of the programmer who need to debug your site is probably usually contained in the above command.

2. Disable Magento maintenance mode

Command usage

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

Show Maintenance Status

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

Command usage

php bin/magento maintenance:status

Exempt IP Addresses From Maintainance Mode

To enable access to the frontend store from a specific IP address while Magento 2 website is in maintenance mode, use the below 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

Above are the shortest method for you to enable/ disable Magento maintenance mode. Whether you are wondering why your Magento 2 website needs to be under maintenance mode or the settings make you a headache, don’t hesitate to contact us.

243 Total Views 2 Views Today