We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
How do Experts Enable and Disable Magento 2 Maintenance Mode?
Magento is a popular Ecommerce application development platform that is leading the global business in today’s time. To leverage the features and capabilities of this platform, developers and IT professionals have deployed a great effort and left no stone unturned. Right away from the empowering it with latest development features to extending the functionalities; Magento has shown a dynamic growth and establishment in recent few years.
Enabling and disabling the Magento maintenance mode is another such extended capability that has surpassed and completely ruled its competitors across the globe.
So, let’s find out the process of enabling and disabling Magento 2 maintenance mode.
What is Magento maintenance mode?
Magento maintenance mode is a condition where the website is turned off bootstrapping. When the Magento is turned into maintenance mode, the visitors will see the message service as temporary unavailable rather than the magento ecommerce website in the browser. The following condition will be
- If var / .maintenance.flag doesn’t exist: Maintenance mode will turn off, and Magento will work normally.
- If var / .maintenance.flag exists: Maintenance mode is on, except where var / .maintenance.ip is present.
Things that you should remember before configuring to magento maintenance mode are:
- You need to get login to Magento application serve with written permission
- Add the below mentioned command to the system
- Use cd <your Magento install dir> /bin and run them as ./magento <command name>
- Or php <your magento install dir> /bin/magento <command name>
How to Enable or Disable Magento 2 Maintenance Mode?
Select the correct working directory
So before you switch to Magento 2 maintenance mode, you need to follow the following steps:
Login to the SSH account
Enter the command: cd ~/public_html
In case you have already installed Magento 2 in your subdirectory, you need to point to that directory. For instance, if you did install Magento in the subdirectory named mag1, you should type:
cd ~/public_html/mag1
Enable an IP address to get accessibility of your online ecommerce store
Enter the command:
bin / magento maintenance: allow-ips xxx.xxx.xxx.xxx
In which, xxx.xxx.xxx.xxx is the IP address you want to allow access to.
Allow the maintenance mode in Magento 2
To enable Magento website maintenance for a store, enter the following command:
bin/magento maintenance:enable
Further, the visitors will receive a Service Temporarily Unavailable message in their browser. However, in case you access Magento from an authorized IP address, the store will show the display normally.
Use the maintenance template for local content
For localized content, you can use a 503 type error template file. For example, the constructor of the Error Processor class accepts a GET skin parameter to change the layout:
if (Isset($_GET['skin'])) {
$this -> _setSkin($_GET['skin']);
}
You can add this rewrite rule in your .htaccess file to add a skin parameter to the URL.
$_GET['skin'] parameter
Check if the skin parameter exists or not
Set parameters using the rewrite rules below. Here are some examples of rewrite rules:
RewriteCond% {DOCUMENT_ROOT} /var/.maintenance.flag -f
RewriteCond% {HTTP_HOST} ^ sub.example.com $
RewriteCond% {QUERY_STRING}! (^ | &) Skin = sub (& | $) [NC]
RewriteRule ^% {REQUEST_URI}? Skin = sub[L]
Copy the following files:
pub / error / default / 503.phtml to pub / error / sub / 503.phtml
pub / error / default / css /styles.css to pub / error / sub / styles.css
Then, you can edit these files to provide localized content in the 503.phtml file and custom styles in the styles.css file.
Ensure your paths point to your errors directory, and the directory name matches the URL parameter specified in the RewriteRule. In the previous example, a sub directory is used, specified as a parameter in the RewriteRule (skin = sub).
Check the status
To check the status of magento 2 maintenance mode, use the command mentioned below:
bin/magento maintenance:status
Turn off the Magento 2 maintenance mode
In order to turn off the maintenance mode and re-enable the store for all visitors, apply the given command
bin/magento maintenance:disable
You can re-verify if var / .maintenance.flag is present or not. Remember, your Magento website is working properly (maintenance mode is off) when the magento maintenance.flag doesn’t exist.
Conclusion
Magento maintenance has been the top priority of the ecommerce business owners in past few years. This has been the reason that global businesses are widely chasing the Magento maintenance companies for the success of their online ecommerce expedition. One has to get a crisp and clear idea that magento is the one stop solution for a wide range of ecommerce forum across the world. To improve the functionality of this platform you mandatorily need to get the support for magento maintenance. Thus, choose wisely and get the best service provider for your business.