Are you developing, updating or fixing your Magento store?
If yes, then it is suggested to put your Magento store in maintenance mode.
It serves a temporary error notification to your visitors and asks them to come back later as you are working on your website.
Although, authorized IP addresses can still view the store normally.
This article explains how to put your Magento store in maintenance mode.
Enable Maintenance Mode in Magento 1 and 2
1. Enable maintenance mode for Magento 1
- Enable the maintenance mode in Magento 1 by setting the maintenance.flag
- Allow access to specific IPs in maintenance mode
2. Enable maintenance mode for Magento 2
- Enable the maintenance mode in Magento 2 by setting the maintenance.flag
- Allow access to specific IPs in maintenance mode
3. Serve a custom error message when in maintenance mode
Enable Maintenance Mode for Magento 1
To enable maintenance mode for Magento 1, you have to create maintenance.flag file inside the webroot (/data/web/public/maintenance.flag).
You can also make use of n98-magerun to put on maintenance mode-
n98-magerun sys: maintenance
To enable/disable Magento maintenance mode, follow the given steps:
- Log in to your Magento administrator account via SSH.
- Go to the directory where Magento is installed. Type cd ~/public_html
- Open the index.php file in your text editor.
- You have to create maintenance.flag file inside the webroot (/data/web/public/maintenance.flag).
If your site is set to maintenance mode on, an error message like below will appear on the screen-
Allow access to specific IPs in maintenance mode in Magento 1
If you are working on your Magento store while it is maintenance mode, then you and your developer must be able to access the store. You can give access to specific IPs by opening the index.php file and change the following code to-
if (file_exists($maintenanceFile)) { include_once dirname(FILE) . '/errors/503.php'; exit;
TO
$ip = $_SERVER[‘REMOTE_ADDR’]; $allowed_ips = array(‘1.2.3.4’, ‘3.4.5.6’); if (file_exists($maintenanceFile) && !in_array ($ip, $allowed_ips)) { include_once dirname(__FILE__) . ‘/errors/503.php’;    exit;}
Note:- Change the IPs 1.2.3.4 and 2.3.4.5 to the IP addresses you want to give access to.
Enable Maintenance Mode for Magento 2
To enable maintenance mode for Magento 1, you have to create maintenance.flag file inside the var/ directory.
Magento detects maintenance mode as follows:-
- If var/.maintenance.flag does not exist, maintenance mode is off.
- Maintenance mode is on if var/.maintenance.IP exists.
To enable/disable Magento maintenance mode, follow the given steps:
- Log in to your Magento administrator account via SSH.
- Go to the directory where Magento is installed.Â
- Open the index.php file in your text editor.
- You have to create maintenance.flag file inside the var/ directory.Â
touch /data/web/magento2/var/.maintenance.flag
If your site is set to maintenance mode on, an error message will appear on the screen.
Allow access to specific IPs in maintenance mode in Magento 2
Use the bin/magento CLI tool to add specific addresses:-
cd ~/magento2 chmod +x bin/magento bin/magento maintenance:enable —ip=1.2.3.4 —ip=2.3.4.5
When the IP addresses are set in the .maintenance.ip file, you can use n98-magerun to achieve the same:
n98-magerun2 sys:maintenance —on n98-magerun2 sys:maintenance —off
Serve a custom error message when in Maintenance mode
If you don’t like the message that is visible to the users when your Magento store is in Maintenance mode, then you can customize it. For this, you have to add some layout files in the directory from where error pages are served.
For Magento 1- /data/web/public/errors1
For Magento 2- /data/web/magento2/pub/errors
It is not recommended to change make changes directly in the default directory, therefore, first, copy the default directory to another directory.
Magento 1:
cd /data/web/public/errorscp -rv default custom/
Magento 2:
cd /data/web/magento2/errors cp -rv default custom/
Now run the following command to copy local.xml.sample to local.xml
cp local.xml.sample local.xml
Now change <skin>default</skin> to <skin>custom</skin> in both local.xml and design.xml
editor local.xml design.xml
After this change, the content for error pages will be served from /errors/custom rather than from /errors/default.
Now you are ready to put your Magento store on Maintenance mode.
ServerGuy offers customized and dedicated hosting services for eCommerce store owners so that their website loads fast and they don’t lose potential customers. You can contact us directly or leave a comment below. We will get back to you asap.