if you need to have apache web server protect a specific virtual host (website) you need four simple steps.
- Create .htpassword file in a root protected path and add the first user
su - mkdir /var/www/htpassword/ htpass -cm /var/www/htpassword/.htpassword admin
- add more users to .htpassword file
htpass -m /var/www/htpassword/.htpassword username
- add .htaccess to your host public directory (or document root), it will look similar to this
AuthName "Restricted Area" AuthType Basic AuthUserFile /var/www/htpass/.htpasswd AuthGroupFile /dev/null require valid-user
this is simple and obvious, but in case of ruby on rails you need to add it to your public directory not rails project root directory.
now, you need to restart your apache websrever to update to latest configuration, then point your browser to your website and check it’s working, it should prompt you for username and password.
have a nice sys admin!