在UBUNTU 14上给PHP写入权限,file_put_contents不起作用

I have to create a script that runs through crontab. I have set up a new Ubuntu in a virtual machine and started testing

So I realized PHP is not writing files (with file_put_contents) in the /var/www/html/ folder when I run the script in the Terminal (sudo php filename.php)

If I remove sudo from the command it says permission denied. I also tried to create a different folder inside ../html/ and also tried chmod 777. nothing seems to work. I've seen this problem a few years ago but I can't find any solution

Does any of you know what is happening?

Check the php executable file to see if setuid permissions are causing PHP to drop the superuser privileges you've given it with sudo.

I know you aren't running this via a web server, but for the benefit of others who do, I find it much too scary to run PHP with elevated privileges. If I really need to do something dangerous, I isolate it to as little code as possible, and code it as a perl script with suid root. (No, you can't do this on shared hosting.) Then I pop out to perl from PHP. In this case, perl automatically runs in taint mode, forcing you to cleanse all your inputs before proceeding. (This technique is from circa 2001, there may be a better way now.)

...Tom Robinson