The problem is that I had to give sites directory and all subfolders and files of it permissions 777 in order for drupal to recognize this folder and not redirect me to install.php page. But on a virtual hosting I noticed that sites is a protected folder and all of its content esspecially sites/default/settings.php with 550 permissions. I did not get the magic trick here, how does drupal recognized that folders. I have created drupal's folders and files both as root and other sudo users, but it did not help. And drupal still see only sites with 777 permissions.
2 Answers
You need to insure that the php process (web server) is a member of the group for the Drupal files. You should make sure that the owner of the files is some user other than the php process / web server, because you do not want to allow the web server to overwrite the Drupal code files.
To change the group of all of the files in your root:
sudo chgrp -R webgroup /path/to/drupal
To add a group to the web server user:
sudo usermod -a -G webgroup www-data
For more advice on correctly setting file permissions for Drupal, see Securing File Permissions and Ownership.
Edit: It was suggested that this answer be expanded to point out that the above page contains a script for setting your permissions. There is also a Drush command for setting permissions in progress at http://drupal.org/node/990812. Both of these scripts can be helpful, but only if you set the user and group ownership of your files correctly, and insure that the web server user is a member of the applicable group as explained above. Please read the quoted page carefully, as it explains these concepts.
try this just replace "USER" with your login name without the Quotations this should solve all permission problems
cd /var/www
sudo chown -R "USER":www-data .
sudo chmod -R 750 .
find . -type d -wholename "*/sites/*/files" -exec sudo chmod -R 770 {} \;
sudo chmod g+s .
find . -type d -exec sudo chmod g+s {} \;
this will set all the permissions as suggested by drupal if the problem still persists then the problem isnt with permissions