Recommended reading

Protect Folder On Apache With Username And Password Login Using .htaccess

July 31, 2019 by Andreas Wik

There is an easy way to password protect folders on your Apache server with username and password.

First, create a new file inside the folder named .htaccess and add the following, which will prompt the user with a login window.

AuthName “New Design Protected Folder“
AuthUserFile .htpasswd
Require valid-user


Next, we need to create another file in the same folder which we reference on line 3 above: .htpasswd. You can place this file in another folder if you wish, but then you’ll need to provide the full path, e.g. AuthUserFile /folderA/folderB/.htpasswd.

This file will include our username and an encrypted version of our password separated with a comma.



Go here to generate the encrypted version of your password. For example, summer123 becomes OI884hHhiiie.

Upload these two files to the folder on your server, restart the server, and you should now be prompted with the following when you try to visit it:


Create more than one login

In .htpasswd you can create as many logins as you wish. One per line.



Great stuff 🙂

Recommended reading

Share this article