Add Basic Auth to Local site

Hey @Mamaduka,

The example above will only work on Linux. Here’s how you can configure Basic Auth on macOS with Local Lightning.

  1. Use htpasswd to add a user to an .htpasswd file in the site’s app directory. Example command (be sure to adjust the path to the site and change EXAMPLE_USER):

    htpasswd -c ~/Local\ Lightning\ Sites/basic-auth/app/.htpasswd EXAMPLE_USER
  2. Add the following to the site’s conf/nginx/includes/wordpress-single.conf.hbs right before the try_files directive (edit wordpress-multi.conf.hbs if the site is multisite)

    auth_basic           "Please log in";
    auth_basic_user_file /PATH/TO/SITE/app/.htpasswd; 

    So, for me, conf/nginx/includes/wordpress-single.conf.hbs becomes…

     # WordPress single blog rules.
     # Designed to be included in any server {} block.
     # This order might seem weird - this is attempted to match last if rules below fail.
     location / {
     	auth_basic           "Please log in";
     	auth_basic_user_file "/Users/claygriffiths/Local Lightning Sites/basic-auth/app/.htpasswd"; 
     	try_files $uri $uri/ /index.php$is_args$args;
     # Add trailing slash to */wp-admin requests.
     rewrite /wp-admin$ $resolved_scheme://$host$uri/ permanent;
  3. Restart the site so the config takes effect

1 Like