Enabling Maintenance Mode
It may sometimes be necessary to prevent public access to a site, for instance while moving an ecommerce site to a new server.
Craft has a System Status status setting for doing this. Within the Control Panel, it can be found under Settings->General->System Status.
The setting can be controlled via an environment variable but we don't need to create a custom one (unless you really want to). By using one of Craft's in-built environment variables (starting with CRAFT_) we can control this setting from outside of the Control Panel
CRAFT_IS_SYSTEM_LIVE=true # true|false
Note Using the CRAFT_ environment variable there is no need to specifically set the Control Panel switch as they will automatically be applied within the site's config files. They will override everything.
What happens?
With the site status set to off any visitor to the front-end of the site who is not logged in to the control panel will see a 503 error page.
Site admins can still see the front-end of the site by first logging in to the Control Panel.
Customizing the page
We can customise this page by creating a template named offline.twig
in the templates directory (if a custom errors folder is set then the template should be in there). The template can still use Craft Entry data if you like.
Note When the site is in dev mode, the 503 Exception page will always be shown. So in your local environment, turn dev mode off to see the offline template.