1. Create a .htaccess file

AuthName "Secure Area"
AuthType Basic
AuthUserFile /path/to/your/directory/.htpasswd
require valid-user

2. Create a .htpasswd file under the account using this command

htpasswd -c .htpasswd your-user-name
and give the password

3.  If you have more than one user, then
htpasswd .htpasswd another-user-name

4. Make sure the permission of file .htpasswd is 644