Password protecting a directory on the server
Here's the basics of password protecting a directory on your server.
You'll need to create a password file. This file should be placed somewhere not accessible from the web. This is so that folks cannot download the password file. For example, if your documents are served out of /usr/local/apache/htdocs you might want to put the password file(s) in /usr/local/apache/passwd.
In the passwd file
htpasswd -c /usr/local/apache/passwd/passwords test
Here test is the username.It will ask password like this.
New password: hiox
Re-type new password: hiox
Adding password for user test
Next, you'll need to configure the server to request a password and tell the server which users are allowed access. You can do this either by editing the httpd.conf file or using an .htaccess file.
In .htaccess file write the below code.
AuthName "Restricted Files"
Require user test
Now the directory htdocs is protected.