Password protecting a folder using .htaccess and .htpasswd.
First step : Create a .htaccess file in the root of the folder which need to be protected. For example, if we need to protect a website, which is access as, something.com/wordpress/, the .htaccess file need to be inside wordpress/ folder since we need to protect all the contents inside it.
The .htaccess file should be;
AuthName “Password protected Area”
This is a basic .htaccess file. First give the username.
Second step : Create the .htpasswd file. Inorder to create it, type in the following command in the console.
htpasswd -c .htpasswd
This command will create the .htpasswd file in the current location. Please note ‘-c’, here means to create a new .htpasswd file. If you do not include this, we can append to an existing file. If you need to create the .htpasswd file in another location, you can directly give the location of the .htpasswd file.