First, create an .htaccess file inside the directory you want to protect with a basic authentication prompt. In this example, we'll protect the folder «test»:

Similarly, create another file named .htpasswd.
Add the following code to the .htaccess file you created:
AuthUserFile — absolute path to the .htpasswd file (explained below).
AuthName "Hello world" — message "Hello world" shown in the login prompt (note: Cyrillic is not supported).
Here is what it should look like:

In our example, the .htpasswd file will also be placed in the «test» directory.

In .htpasswd stores username + hashed password pairs. For example:
Usernames can include Latin letters, numbers, «–», and «_». They are case-sensitive.
To generate a hashed password, use a password generation utility.
Insert the generated line into your .htpasswd file and save the changes.
Done — your «test» directory is now protected with basic authentication.
