Password-protect Parts of Your Website

password-protect (2)

Prerequisites

You will need a running ubuntu server to follow the steps in this article.

Setup

  1. Enter in terminal:
    sudo apt-get update
    sudo apt-get install apache2 apache2-utils
    sudo htpasswd -c /etc/apache2/.htpasswd some-username
    sudo nano /etc/apache2/sites-enabled/000-default.conf
    
  2. Add:
    <Directory "/var/www/html">
            AuthType Basic
            AuthName "Restricted Content"
            AuthUserFile /etc/apache2/.htpasswd
            Require valid-user
    </Directory>
    

    Replace /var/www/html with the path to the directory you want to restrict access to.

  3. sudo service apache2 restart

Voila!

Leave a Reply

Your email address will not be published.