Basic HTTP Authentication in Drupal Site Using settings.php

Here’s a quick and painless way of preventing public access to a Drupal site using settings.php (or settings.local.php).

I’ve been using this for development and staging sites that I want to keep private.

If you want this to be available to all settings*.php files you should put this near the top of your settings.php file:

Then, you can leverage it wherever you’d like. For example, on an Acquia site I might add this to the bottom of settings.php:

For┬ánon-Acquia sites I’d call the function at the bottom of settings.local.php.

Leave a Reply

Your email address will not be published.