Step 1: Create .htaccess file
The first thing you must do is to create a .htaccess file inside the directory that you want to protect. Then the server will firstly check this file before allowing access to the directory. The file must contain these lines:
AuthUserFile /path_to_htpasswd/.htpasswd AuthName "Please login" AuthType Basic
The first line defines the absolute path to the .htpasswd file. The .htpasswd file holds all the usernames and encrypted passwords of users allowed to have access to protected directories in your website. We will create this file in step 2.
The second line defines the message that will be displayed when someone tries to access the directory.
The third line is the type of user authentication.
Step 2: Create .htpasswd file
It is very important that this file is placed outside of the website root. Inside the file you must create users with this format:
You can create as many users as you like, each one on a different line. You can easily generate encrypted passwords with this tool.
Step 3: Define who has access
Now that you have created the users file, add this line to the directory .htaccess file:
if you want to grant access to all users in the list or
require user minitek
if you want to grant access only to the user with the username minitek.