303.473.4400 / Toll Free: 888.772.0777
Select Page

Magento 2.0: How to Create a Custom Maintenance Mode Page - Magento Consulting - Customer ParadigmIn Magento 2.0, there is currently no documented way to set a custom message or page if you want to put your site into maintenance mode. (This is as of August 2015.)

Update: Nov 2015: We’ve turned this into a Free Magento 2.0 Module, to make it easy to put a Magento 2.0 site into maintenance mode, right from the admin area. Download the Custom Maintenance Mode Extension for Magento 2.0 Here >>

For most store owners, if you need to put the site into maintenance mode to upgrade a site, it’s not ideal to use a basic message that looks like there’s a big issue on your site (or that you’ve gone out of business). This is a pretty critical feature for most site owners. When Apple launches a new product, for example, they often put their site into maintenance mode, promising that new products are on the way.

In Magento 1.x, there were many ways to set this, but it took some digging to find a way to set a custom message for a Magento 2.0 site when it’s in maintenance mode.

Background:
To put a Magento 2.0 site into maintenance mode, you need to create a file in the /var/ directory called: .maintenance.flag (In Magento 1.x, this flag was placed in the root Magento directory.)

You can also bypass specific IP addresses to allow them to see the site by creating a file in the /var/ directory called .maintenance.ip with the IP address(es) you want to have in the file.

If you are connecting via FTP, you will want to make sure that your FTP program displays hidden files.
In FileZilla, for example, go to Server –> Force Show Hidden Files:

How to show hidden files in FileZilla - Screenshot.

If you are using SSH to access your site, you’ll want to use the command “ls -a” to show hidden files in a directory.

Different Error Messages for Maintenance Mode in Magento 2.0:

There are three modes in Magento 2.0: default, developer and production. In default and production, the site will display a message like this:

Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

(The title tag shows an Error 503 message)

Here’s a screenshot:

Default Maintenance Mode Message for Magento 2.0: Service Temporarily Unavailable - 503 error message.
View Larger Screenshot – Magento 2.0 – Default Maintenance Mode Message >>

Again, if you are a Website owner, this is not an ideal message to show to your customers.

If you put the site into developer mode by changing a line in the .htaccess file in the root directory here:

############################################
## uncomment the line below to enable developer mode

SetEnv MAGE_MODE developer

Here’s a screenshot:

How to set the Magento Mode to Developer Mode via the .htaccess file in Magento 2.0.
View Larger Screenshot – How to Set Developer Mode in Magento 2.0 >>

then it will display an error message more like this:

Unable to proceed: the maintenance mode is enabled.
#0 /var/www/html/lib/internal/Magento/Framework/App/Bootstrap.php(255): MagentoFrameworkAppBootstrap->assertMaintenance()
#1 /var/www/html/index.php(39): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttp))
#2 {main}

Magento 2.0 Developer Mode - Maintenance Mode displays more verbose errors. Screenshot.

View Larger Screenshot – Magento 2.0 Maintenance Mode Message with Developer Mode On >>

If this is commented with a # mark like this:

############################################
## uncomment the line below to enable developer mode

# SetEnv MAGE_MODE developer

… then your site is in default mode.

Based on the error message you see, you’ll be able to see what mode your Magento 2.0 site is currently in.

How to create a custom Maintenance Mode Page in Magento 2.0:

My first attempt to create a custom message page didn’t work.

I first went into the .htaccess file, and tried to create a rewrite rule for an error 503 server error, and have it redirect to an error page with a line like this:

ErrorDocument 503 site-down-message.html

(But this didn’t work.)

After a bit of digging, I was able to find the correct location in the /pub/ directory:
/var/www/html/pub/errors/default/503.phtml

I then did a quick edit on the 503.phtml file and it works:


View Larger Screenshot – Magento 2.0 Custom Maintenance Mode Web Page >>

Now… This is a down-and-dirty way to create a custom error message. You may want to create a module that will do this instead of changing the default 503 handling error message.

Update: Nov 2015: We’ve turned this into a Free Magento 2.0 Module, to make it easy to put a Magento 2.0 site into maintenance mode, right from the admin area. Download the Custom Maintenance Mode Extension for Magento 2.0 Here >>

Questions about Magento 2.0? Need help? Call Customer Paradigm – 303.473.4400 or visit here to have a real person contact you now >>

 

Pin It on Pinterest

Share This