Magento maintenance mode on steroids

So you have a live site and you need to do some work on it. The first thing you do is enable maintenance mode. But something bad happens when you do that. The whole site is down for everyone, including you. But how are you going to fix the site if you can not even see it? Well, I use something like this.

After you’ve created a file in a root of your Magento website with “maintenance” text in it, site will go in to the maintenance mode. Now if you open your index.php and look around line 64 (Magento version 1.7.0.2). You will see something like this:

1
2
3
4
if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

Now you want to add some IPs so you and some other remote developers can connect to the site. To everyone else you can show your custom under construction template. The code fix is as follows:

1
2
3
4
5
6
7
$ip         = $_SERVER['REMOTE_ADDR'];
$allowed    = array("111.111.111.111", "222.222.222.222");

if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {
    include_once dirname(__FILE__) . '/working.php'; // custom under construction page
    exit;
}

That’s it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *