Enable or disable maintenance mode
The following guide refers to a standard Magento maintenance mode page. If you need to use a custom maintenance page, see Create the custom maintenance page topic.
Magento uses maintenance mode to disable bootstrapping. Disabling bootstrapping is helpful while you are maintaining, upgrading, or reconfiguring your site.
Magento detects maintenance mode as follows:
- If
var/.maintenance.flag
does not exist, maintenance mode is off and Magento operates normally. -
Otherwise, maintenance mode is on unless
var/.maintenance.ip
exists.var/.maintenance.ip
can contain a list of IP addresses. If an entry point is accessed using HTTP and the client IP address corresponds to one of the entries in that list, then maintenance mode is off.
Log in as file system owner
To log in as the file system owner:
-
Log in to the Magento server as, or switch to, a user with permissions to write to the Magento file system. See switch to the file system owner.
If you use the bash shell, you can use the following syntax to switch to the file system owner and enter the command at the same time:
1
su <file system owner> -s /bin/bash -c <command>
If the file system owner does not allow logins, you can do the following:
1
sudo -u <file system owner> <command>
-
To run Magento commands from any directory, add
<magento_root>/bin
to your systemPATH
.Because shells have differing syntax, consult a reference like unix.stackexchange.com.
Sample bash shell for CentOS:
1
export PATH=$PATH:/var/www/html/magento2/bin
Optionally, you can run the commands in the following ways:
cd <magento_root>/bin
and run them as./magento <command name>
<magento_root>/bin/magento <command name>
<magento_root>
is a subdirectory of your web server docroot.
In addition to the command arguments discussed here, see Common arguments.
Install Magento
Before you use this command to enable or disable maintenance mode, you must install the Magento software.
Enable or disable maintenance mode
Use the magento maintenance
CLI command to enable or disable Magento maintenance mode.
Command usage:
1
bin/magento maintenance:enable [--ip=<ip address> ... --ip=<ip address>] | [ip=none]
1
bin/magento maintenance:disable [--ip=<ip address> ... --ip=<ip address>] | [ip=none]
1
bin/magento maintenance:status
--ip=<ip address>
is an IP address to exempt from maintenance mode (for example, developers doing the maintenance). To exempt more than one IP address in the same command, use the option multiple times.
Using --ip=<ip address>
with magento maintenance:disable
saves the list of IPs for later use. To clear the list of exempt IPs, use magento maintenance:enable --ip=none
or see Maintain the list of exempt IP addresses.
magento maintenance:status
displays the current status of maintenance mode.
For example, to enable maintenance mode with no IP address exemptions:
1
bin/magento maintenance:enable
To enable maintenance mode for all clients except 192.0.2.10 and 192.0.2.11:
1
bin/magento maintenance:enable --ip=192.0.2.10 --ip=192.0.2.11
After you place Magento in maintenance mode, you must stop all message queue consumer processes.
One way to find these processes is to run the ps -ef | grep queue:consumers:start
command, and then run the kill <process_id>
command for each consumer. In a multiple node environment, repeat this task on each node.
Maintain the list of exempt IP addresses
To maintain the list of exempt IP addresses, you can either use the [--ip=<ip list>]
option in the preceding commands or you can use the following:
1
bin/magento maintenance:allow-ips <ip address> .. <ip address> [--none]
<ip address> .. <ip address>
is an optional space-delimited list of IP addresses to exempt.
--none
clears the list.
Multi-store setups
To set up multiple stores, each with a different layout and localized content, create a skin for each and put it into pub/errors/{name}
where {name}
is the store code. To distinguish between stores and websites with the same instance, use pub/errors/{type}-{name}
where {type}
is either store
or website
and matches the MAGE_RUN_TYPE
in your server configuration.
Another option is to pass the $_GET['skin']
parameter to the intended processor. This method requires a specific configuration on your server.
In the following example, we are using a 503
type error template file, which requires localized content.
The constructor of the Error_Processor
class accepts a skin
GET parameter to change the layout:
1
2
3
if (isset($_GET['skin'])) {
$this->_setSkin($_GET['skin']);
}
This can also be added to a rewrite rule in the .htaccess
file that will append a skin
parameter to the URL.
$_GET[‘skin’] parameter
To use the skin
parameter:
- Check if the
.maintenance.flag
exists. - Note the host address, that refers to the
HTTP_HOST
, or any other variable such as ENV variables. - Check if the
skin
parameter exists. -
Set the parameter by 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]
- RewriteCond
-
Copy the following files:
pub/errors/default/503.phtml
topub/errors/sub/503.phtml
pub/errors/default/css/styles.css
topub/errors/sub/styles.css
-
Edit these files to provide localized content in the
503.phtml
file and custom styling in thestyles.css
file.Ensure your paths point to your
errors
directory. The directory name must match the URL parameter indicated in theRewriteRule
. In the previous example, thesub
directory is used, which is specified as a parameter in theRewriteRule
(skin=sub
)
The nginx setting must be added for multi-store setups.