First Go to your website’s root directory. In this article, website root directory is. “/var/www/html”

cd /var/www/html/
nano -w .htaccess

Insert this to .htaccess

AuthName "Restricted Access"
AuthType Basic
AuthUserFile /var/www/html/.htpasswd
require valid-user

Ctrl+x then y for Save and close the file.

Create password with .htpasswd file

htpasswd -c .htpasswd tester
New password: 
Re-type new password: 
Adding password for user tester

Check password file.

cat .htpasswd

password is encrypted we can’t read it.

Edit httpd.conf to allow AllowOverride ALL

In this article the httpd.conf file stored on directory “_/etc/httpd/conf/” _if you don’t know where it is, you can use command “locate httpd.conf” it’s will return you a path of httpd.conf file at your server.

nano -w /etc/httpd/conf/httpd.conf

Ctrl+w then search “<Directory “” and change AllowOverride none to AllowOverride ALL

&lt;Directory "/var/www/html"
&gt; AllowOverride ALL

Ctrl+x then y for Save and close the file.

Restart httpd:

service httpd restart

Now go to website, It will ask you for authentication.