How to Enable Magento 2 Maintenance Mode?
[Updated On April 28, 2025] Imagine refreshing your shop without risking downtime and customer loss? Magento 2 maintenance mode lets you update your site without disrupting customer journey. In maintenance mode, customers see 'Under Maintenance' message instead of store's frontend.
Learn how to enable and set up Magento 2 maintenance mode for updates with this tutorial.
Key Takeaways
-
Magento maintenance mode is a safe way to update store without affecting visitors.
-
The command line controls enable or disable maintenance mode in Magento.
-
Specific IP addresses can still access the store during maintenance mode.
-
A custom maintenance page helps maintain user interest during downtime.
-
Zero-downtime rollouts and CLI tools for smoother maintenance operations.
What is Magento 2 Maintenance Mode?
Magento 2’s maintenance mode puts a temporary hold on the norms of your site while you tweak, update, or prep it.
Magento 2 checks for maintenance mode with a file called maintenance.flag.
Here’s what happens:
-
If
var/.maintenance.flag
isn’t there, maintenance mode is off. Magento 2 runs as usual. -
If
var/.maintenance.flag
is there, maintenance mode is on. But it’s off for IP addresses listed invar/.maintenance.ip
.
The var/.maintenance.ip
file holds a list of IP addresses. If your IP address is on that list, you see the site. Certain IP addresses can still reach your website. It lets you test and build the site before it goes live or handle tasks like updates and adjustments.
What do You need for Magento 2 Maintenance Mode?
The Magento 2 app or website builder usually manages maintenance mode. If you’re doing it yourself, get these things ready.
Log into the Magento 2 server with file system access, like a web server account. Add this to your system path to run Magento 2 commands from anywhere:
\<your Magento install dir\>/bin
You can run commands these ways:
-
Type
cd \<your Magento install dir\>/bin and use ./magento \<command name\>
-
Or
type php \<your Magento install dir\>/bin/magento \<command name\>
Note: \<your Magento install dir\>
is a folder inside your web server’s document root.
How to Enable or Disable Maintenance Mode in Magento 2 Stores?
1. Pick Your Working Directory
Before you turn on Magento 2 maintenance mode:
-
Log into your SSH account.
-
Enter this command:
cd \~/public\_html
-
If Magento 2 is in a subfolder, go there instead. For example, if it’s in a folder called mag1, type:
cd \~/public\_html/mag1
2. Let an IP Address Reach the Store
To let a specific IP address access the storefront during maintenance mode, type:
bin/magento maintenance:allow-ips xxx.xxx.xxx.xxx
Here, xxx.xxx.xxx.xxx is the IP address you want to let through.
Example - Turn on maintenance mode with no IP address exceptions:
bin/magento maintenance:enable
Example - Turn on maintenance mode but let IP addresses 183.0.2.20 and 183.0.2.21 through:
bin/magento maintenance:enable \--ip=183.0.2.20 \--ip=183.0.2.21
You can clear many IP addresses in one command. Add \--ip=\<ip address\>
as many times as needed. To clear all allowed IP addresses, use:
bin/magento maintenance:enable \--ip=none
3. Enable Maintenance Mode in Magento 2
To switch on maintenance mode for a Magento 2 store, type:
bin/magento maintenance:enable
Visitors see a "Service Unavailable" message. The store looks normal from an allowed IP address.
For stores with different languages and layouts, add $_GET['skin'] parameter to processor. Check that Nginx is installed for those stores.
4. Template File for Local Content
For local content, use a 503 error template file. The r_Processor class constructor takes a GET skin parameter to adjust the layout:
$this-\>\_setSkin($\_GET\['skin'\]);
}
Add a rewrite rule in your .htaccess file to include a skin parameter in the URL.
Check $_GET['skin'] parameter. Confirm Magento 2 is there before using this skin parameter. Note the server address, HTTP_HOST reference, or ENV variables.
Set parameters with these rewrite rules. Here are some examples:
RewriteCond %{HTTP\_HOST} ^sub.example.com$
RewriteCond %{QUERY\_STRING} \!(^|&)skin=sub(&|$) \[NC\]
RewriteRule ^ %{REQUEST\_URI}?skin=sub \[L\]
Copy these files:
-
pub/errors/default/503.phtml to pub/errors/sub/503.phtml
-
pub/errors/default/css/styles.css to pub/errors/sub/styles.css
Edit these files for local content in 503.phtml and custom styles in styles.css.
The paths point to your errors folder. The folder name matches the URL parameter in the RewriteRule. In this case, it’s a subfolder tied to the skin=sub parameter.
Note: Add Nginx settings for multi-store setups.
5. Check Magento 2 Maintenance Status
See your Magento 2 maintenance mode status with:
bin/magento maintenance:status
6. Disable Maintenance Mode in Magento 2
Switch off maintenance mode and open the store to all visitors with:
bin/magento maintenance:disable
Look for var/.maintenance.flag
. If it’s gone, the site works fine, and maintenance mode is off.
What are New Trends in Magento Maintenance Mode?
1. Zero Downtime Updates
New tricks let you update Magento 2 without downtime. Developers can tweak and maintain sites while users stay unaffected. Use commands like:
bin/magento magefan:zero-downtime:deploy
It keeps customers in your store during updates and changes.
2. Custom Maintenance Pages
More stores now make personal maintenance pages to keep customers interested. Tools like Coming Soon Page add countdown timers, branding, and social media links. It holds customer attention during breaks and gives your store a sharper look.
3. Easy Command-Line Tools
Command-line tools got simpler. They make handling maintenance mode a breeze:
php bin/magento maintenance:disable
php bin/magento maintenance:status
These commands run maintenance mode and ease site upkeep for store admins.
4. Stronger Security and Performance
Smart habits now push backups, safe access, and solid performance during maintenance mode. Set developer mode to stop cached content from messing with maintenance pages:
bin/magento deploy:mode:set developer
It keeps your maintenance work safe and quick.
FAQs
1. How can I enable or disable maintenance mode in Magento 2?
You need server access to manage maintenance mode. Use the command line to enable maintenance mode. Run: bin/magento maintenance:enable
. Customers will receive a “Service Unavailable” message.
To re-enable the site, run: bin/magento maintenance:disable. This command disables maintenance mode and brings back the access.
2. When should I use Magento maintenance mode?
Maintenance mode in Magento 2 pauses your store's frontend for a short time. It lets you update, fix, or configure the store without interruptions. Visitors cannot access the site. You can still view the store from approved IP addresses.
Use maintenance mode when you want to avoid showing errors or incomplete changes. Disable Magento 2 maintenance mode when your updates are complete.
3. How do I allow access to certain users during Magento maintenance?
You can let specific users bypass Magento maintenance mode. Add IP addresses using the command: bin/magento maintenance:allow-ips xxx.xxx.xxx.xxx
. Replace the placeholder with the real IP.
This command allows access during maintenance mode from that IP address. You can add different addresses in the same command.
4. What command to use to disable Magento 2 maintenance mode?
Use bin/magento maintenance:disable
to disable Magento 2 maintenance mode. This command removes the maintenance flag file.
The site becomes accessible to all visitors. Run this only when you have finished your updates or fixes.
5. Why is it important to enable or disable maintenance mode in Magento during updates?
Always manage maintenance mode during store changes. Enable maintenance mode before applying updates. It prevents Magento customers from seeing broken features or unfinished work.
After completing the updates, disable maintenance mode. Doing this ensures customers get a stable and smooth experience. You control visibility while keeping the store safe.
Summary
You can enable Magento 2 maintenance mode to test your site before it goes live. Use it for updates, fixes, and setup too. Key benefits are:
-
Zero Downtime: Update your store without affecting visitors.
-
Custom Maintenance Pages: Keep customers engaged with personalized messages.
-
IP Access Control: Allow specific IP addresses to view the store during maintenance.
-
Enhanced Security: Safeguard your store with stronger backup and access features.
Want faster updates and fewer store issues? Try managed Magento hosting today. [Updated On April 28, 2025]