Weird permissions problems for sites/default/files I have this weird problem related to permissions on a VPS where I run 2 Drupal 7 websites.

I have an old site, which was migrated over several hosting providers and VPS setups. I also have a freshly installed website.

The new one works perfectly and I can set it to aggregate and compress CSS files plus JavaScript files. All is smooth and without errors.

The old one... each time I set it to do this, It gives me errors such as: 

The specified file temporary://filepIYgt4 could not be copied to public://js/js_IaQHoIpFqzgiVl19GZEd2HEQg6iqLy6d1_xllBmEbqE.js.
The specified file temporary://fileTbJH3r could not be copied to public://css /css_Lnc8IK4qbp4ueX76wBYIBGAqVihLWtCHHNP7WBSphEM.css.


Both websites are configured the same way. The difference though seems to be in the permissions set for the sites/default/files folder. The new website (which works fine) has the permissions set to 0777 and the group and owner are set to apache.

The old website (which generates errors) has the permissions set to 0777, the group to psacln and the owner is the user I'm using to login to the website via SSH or FTP.

If I change the owner and the group to apache for the old website, things still don't work. I get warnings like these:

Warning: realpath(): SAFE MODE Restriction in effect. The script whose uid is 10002 is not allowed to access /var/www/vhosts/.../httpdocs/sites/default/files/css owned by uid 48 in DrupalLocalStreamWrapper-&gt;getLocalPath()

Warning: realpath(): SAFE MODE Restriction in effect. The script whose uid is 10002 is not allowed to access /var/www/vhosts/.../httpdocs/sites/default/files/js owned by uid 48 in DrupalLocalStreamWrapper-&gt;getLocalPath()

Warning: realpath(): SAFE MODE Restriction in effect. The script whose uid is 10002 is not allowed to access /var/www/vhosts/.../httpdocs/sites/default/files/ctools owned by uid 48 in DrupalLocalStreamWrapper-&gt;getLocalPath()


As you can see, Drupal still can't write to the same troublesome folder. :(

What am I doing wrong? Any advice how to fix this?
I managed to figure this out with the help of the company providing the hosting. So, I'm sharing the solution, in case others have similar issues.

The solution is to make PHP run as a "FastCGI application", instead of an "Apache module". This way, Drupal uses the same user I use to upload files via FTP, when it creates files, etc.

The new website worked fine because I used the one-click installer offered by the hosting provider, which ran everything using the apache user. The old website did not do this.

This solution &amp; problem should apply to all hosting providers using Plesk.