Password-protect Parts of Your Website

April 2016


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


  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
    Replace /var/www/html with the path to the directory you want to restrict access to.
  3. sudo service apache2 restart


Become a better web developer by staying up to date