User Tools

Site Tools


wiki:password_protect_site_htaccess

Password protect site with htaccess in Apache

Create the Password File

  apt-get install apache2-utils
  htpasswd -c /etc/apache2/.htpasswd <username>

In vhost conf add:

  AuthType Basic
  AuthName "Restricted Content"
  AuthUserFile /etc/apache2/.htpasswd
  Require valid-user

Example protecting the directory:

  <Directory /var/www/example>
          AllowOverride All
          Options FollowSymlinks
          AuthType Basic
          AuthName "Restricted Content"
          AuthUserFile /etc/apache2/.htpasswd
          Require valid-user
  </Directory>
  

Example protecting the URL:

  <Location /admin>
      AuthUserFile /var/www/htpasswd/.htpasswd
      AuthName "Password Protected Area"
      AuthType Basic
      Require valid-user
  </Location>

Do it for both non-ssl and ssl vhost configuration

Check conf and reload web server

apachectl -t
systemctl reload apache2

See also

References

wiki/password_protect_site_htaccess.txt · Last modified: 2022/04/17 12:47 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki