Mon Apr 12 01:06:49 EEST 2010

Password Protecting single file with htaccess password / Securing single exetubale in Apache with password through htaccess

I have a running awstats installation and needed a way to protect the cgi-bin statistics with a password. Thanksfully there is a way to achieve that through the Apache. To secure your let's say awstats.pl or any other /cgi-bin/ executable with a password here is what you need to do:

First make sure you have:
Allowoverride All directive enabled in your Apache Directory permissions for the /cgi-bin/.

Next you will need to create an .htaccess file in your /cgi-bin/ directory . The file should contain something close to:

<FilesMatch "awstats.pl">
AuthName "Login Required"
AuthType Basic
AuthUserFile /var/www/awstats/.htpasswd
require valid-user
</FilesMatch>


Note that you need to paste the Filesmismatch in a proper syntax otherwise that won't work, I quote it without the less than and greater than signs intentionally :)
The above example presumes that you have created the .htpasswd in /var/www/awstats/.
To create this file issue the command:

debian:~# htpasswd -c /var/www/awstats/.htpasswd admin


That's all now your awstats installation or any other executable specified in FileMatch would be created with a password.