How to enable maintenance mode in Magento

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.

To set Magento in maintenance mode you need to create a file with name “maintenance.flag” and drop it to Magento home directory. While this file exists your website visitors will see a temporary page (/errors/503.php). If you want to edit this page content you can find it in Magento admin – CMS/Pages, it is called “503 Service Unavailable”.

Once you finished with changes and your website is ready to work just delete maintenance.flag file and maintenance mode will be off, so your Magento website will work as usual.

All we need to do it edit 3 lines.

Open: index.php in root and above line 57 add (remembering to edit the ‘allowed’ array to contain the IP’s you want to be able to access the site);

$ip = $_SERVER['REMOTE_ADDR'];
$allowed = array('1.1.1.1','2.2.2.2'); // these are the IP's that are allowed to view the site.

then change the line
if (file_exists($maintenanceFile)) {
to
if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {

Simple. Now you can access the site, while others see its maintenance mode.