I have setup LAMP on my ubuntu 12.04 system. I want to set password for all the files inside the root folder of Apache, so that only authorized people can use them. How do I set password for the folders?
You don't want to password protect the files in this instance, but rather decide who should be allowed to touch the files. It is the user accounts that should be protected with passwords (or other means like keys). Anything else would apply sharing passwords between users, which is Always Wrong.
What you want to do, is to set ownership of the files and directories. That's simple:
In the example above, I've set ownership to www-data because this user needs access in order for you to publish these files. I've set "groupname" as the group owner. You can use your own primary group, which is the same as your username. In this case, only you and the server will be able to manage those files.
If you want more than one local user to be able to manage the content, then you want to create a new group, add the relevant users to that group and make that the group owner. Let's say you want the existing users "joe", "john" and "gina" to be allowed to read and edit the files in the /var/www/ directory. Everyone else should have no access to that folder at all.
The last line is what removes "others" rights to read, access or write to any files in /var/www.
You can use Basic authentication to do that. For example: