First generate your htppasswd file:
#htpasswd -c htpasswd user_name
assume we put the file in
Second, assume the site you want to protect is called test.mysite.com on port 80
Put the following for your http configuration. In Ubuntu, it will be a file in your /etc/apach2/sites-enable/ directory
setEnvIfNoCase HOST ^test\.mysite\.com\.?(:80)?$ PROTECTED_HOST
#put this in your location directive
AuthName "this site is password protected :)"
Deny from all
Allow from env=!PROTECTED_HOST
This configuration, will pop up password for test.mysite.com on port 80.