Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maintenance.flag file usage

When I first started using Magento and I first made a backup, I ticked the "put website into maintenance mode" button. Once this was done when I tried to visit my site I was given a 503 error (I think). I found that this was due to Magento creating a maintenance.flag file.

I've come to understand that this is used to stop people accessing your site when you are updating things or backing up.

Is it possible to use a maintenance.flag file to block people from visiting your site while you're physically updating and checking? I have 2 servers a test and a live server. The live server uses SSL and is much faster than the free testing server that I have. Currently I'm developing changes on the test server and then uploading to the live server once I know it al works and looks OK.

Since we applied the SSL to the live server. Certain things are (or are not) happening when I do updates. I'm wondering if I can temporarily block access to my site while I check my updates then allow people back on.

The maintenance.flag file blocks me out of my site as well so as far as I can understand what I want to do is not possible.

like image 553
AndrewBramwell Avatar asked Jul 22 '26 02:07

AndrewBramwell


2 Answers

Yes, it's possible to set Maintenance Flag and then have your index.php check for a set of addresses that are let through while serving everyone else a 503 page. Only those systems will be allowed admin and public access while maintenance.flag is set. Find the section in index.php and make some modifications. I use the following on Magento 1.4.2.0, check to make sure 1.7 uses the same mechanism in index.php:

$maintenanceFile = 'maintenance.flag';
$ip = $_SERVER['REMOTE_ADDR'];

/***************
 * IP's allowed in maintenance.
 * Use publicly visible IP addresses on LIVE, local if on DEV
 ***************/

$allowed = array('10.0.0.100','10.0.0.101','10.0.0.20');

if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {
    $basePath = dirname($_SERVER['PHP_SELF']);
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}
like image 171
Fiasco Labs Avatar answered Jul 26 '26 04:07

Fiasco Labs


Store Maintenance : http://www.magentocommerce.com/magento-connect/store-maintenance.html

This extension will take care of your needs.

like image 22
Oscprofessionals Avatar answered Jul 26 '26 04:07

Oscprofessionals



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!