Maintenance mode is not only an important but useful mode in Magento. This mode is enabled in case you want to disable your website temporarily prior to making it live or performing maintenance tasks such as bug fixing, updating, etc. When your website is in maintenance mode, store visitors receive a Service Temporarily Unavailable message in their web browser rather than the frontend store. But you can access it from authorized IP addresses for checking the store normally.
Steps to Enable and Disable Maintenance Mode in Magento 1
1. Login to your Magento administrator account using SSH.
2. Switch to the directory where Magento is installed. For instance, if you installed Magento in the document root directory, type the below command:
cd ~/public_html
3. Using your preferred text editor, open the index.php file.
4. Paste the below line in the index.php file:
$maintenanceFile = 'maintenance.flag';
5. Add the below two lines after this. Where xxx.xxx.xxx.xxx is the IP address for which you want to enable the access to the front-end store while Magento is in maintenance mode.
$ip = $_SERVER['REMOTE_ADDR']; $allowed = array('xxx.xxx.xxx.xxx');
Note: To discover multiple IP addresses from the maintenance model, separate them with a comma.
For example:
$allowed = array('10.1.0.127','10.1.0.252');
6. For knowing your own IP address, access the website: http://ipfinder.us/
7. Add the below line in the index.php file:
if (file_exists($maintenanceFile)) {
8. Change the line in the following way:
if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {
9. Save your changes to the index.php file and close the editor.
10.On the command prompt enter the below command:
touch maintenance.flag
Once you complete with the above steps, your status is set to maintenance mode. After accessing the Magento website from an authorized IP address, the store will display normally. But when your visitors browse the website, they will get a Service Temporarily Unavailable message displayed.
For disabling the maintenance mode and allowing the access of the frontend store to all visitors, type the following command:
rm maintenance.flag
Steps to Enable or Disable Maintenance Mode in Magento 2
Magento detects the maintenance mode in the below way:
- If var/.maintenance.flag is not available, the maintenance mode is off and Magento website runs normally.
- If var/.maintenance.flag is present, the maintenance mode is on.
But, the maintenance status is also based on the file var/.maintenance.ip. There will some exceptions made by this file to turn off the Magento 2 maintenance mode even if var/.maintenance.flag is present.
1. Login to your account using SSH.
2. Go to the file where your Magento is installed in.
3. Add the below command to the command prompt of SSH:
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
4. With the use of the above command, you will enable the maintenance mode for two IP addresses 192.168.1.10 and 192.168.1.11. The developer’s IP address who wants to debug your website is usually included in the above command.
5. To disable the maintenance mode use the below command:
php bin/magento maintenance:disable [--ip=<ip address>]
6. To check the current status of the maintenance mode, use the below command:
php bin/magento maintenance:status
Steps to Exempt IP Addresses From Maintainance Mode
For enabling the access to the frontend store from a specific IP address when you put Magento website in maintenance mode, type the below command:
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
Conclusion
The above are the short and simple processes to enable/disable maintenance mode in Magento 2. This guide will help you to manage the maintenance mode in Magento easily.