I'm trying to handle a planned database outage and want Drupal to show the maintenance page during that time.

  • $conf['maintenance_theme'] = 'exampletheme' and a suitable $conf['_message'] are set in my sites/sitename.com/settings.php
  • I have a maintenace-page--offline.tpl.php and maintenance-page.tpl.php in sites/all/themes/exampletheme/templates/
  • I set $conf['maintenance_mode'] = TRUE in sites/sitename.com/settings.php

I hope that Drupal that does not have a database can still bootstrap and display the contents of maintenance-page--offline-tpl.php in this configuration, but in my testing it seems that's not the case. Should this work? Anything I should look into?

  • Have you seen this: drupal.stackexchange.com/questions/165699/… ? Commented Feb 5, 2018 at 22:33
  • @brotherperes I've read through that now and followed the instructions and it seems it's not working. So, I guess this question is asking for help to understand why this feature is not working for me.
    – greggles
    Commented Feb 5, 2018 at 23:18
  • Well there is one way to find out, Are you thinking what I'm thinking?
    – No Sssweat
    Commented Feb 6, 2018 at 6:24
  • yes. Clone the website to a different location first. I've got the process to do that if you need. Commented Feb 6, 2018 at 10:58
  • I'd say no you'd need a database working as the variable that defines if the site is/isn't in maintenance mode is itself stored in the database. A dirty but quick workaround would be to temporary hack the index.php and do a print 'Site in maintenance mode'; die; or something similar
    – Leigh
    Commented Feb 6, 2018 at 14:42

2 Answers 2


What you're describing should work: the maintenance-page--offline.tpl.php template should be called when the database is unavailable.

Drupal does not bootstrap completely when there is no database, but does so partially. When the bootstrap process fails to contact the database, it calls _drupal_log_error() in include/errors.inc, which (indirectly) calls _drupal_maintenance_theme() in includes/theme.maintenance.inc. This is enough to allow hook invocations to work, and to load the theme specified in your $conf['maintenance_theme'] setting.

First, I would verify that _drupal_maintenance_theme() is being called and that it's finding your theme. If you're using a debugger, set a breakpoint there. If not, add this line at the end of the function:

  echo "<p>Custom theme: $custom_theme</p>";

If all is ok up to this point, try starting off with the simplest possible maintenance page in maintenance-page--offline.tpl.php, e.g.

<h1>Hello world</h1>

If that works, and your maintenance page does not, perhaps your maintenance page contains something that attempts to access the database, or invokes a hook that attempts to access the database? Can you post your template and any errors you are seeing?

If the simple maintenance page doesn't work, more debugging would be needed.


I know its not the question, but in case it is helpful for Drupal 8, 9, 10, etc, you can render a twig template like this via your settings.php/settings.local.php:

$loader = new \Twig\Loader\FilesystemLoader(DRUPAL_ROOT . '/themes/custom/theme-name/templates/maintenance/');
$twig = new \Twig\Environment($loader);
$filter = new \Twig\TwigFilter('t', function ($string) {
  return $string;

This assumes you have added a twig file named 'maintenance-page.html.twig' in 'theme-name' theme within the 'templates/maintenance' folder.

Delete this snippet of code from your settings.php/settings.local.php when you are done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.