Running a php script to delete something
sth is a directory with the status:
drwxr-sr-x 2 www-data www-data 4096 Jan 11 12:58 sth
An everything in it has the status:
-rw-r–r-- 1 www-data www-data 5189 Jan 11 12:58 blahblahblah
The phpscript.php status is:
-rw-r–r-- 1 myuser www-data 544 Jan 10 07:00 phpscript.php
Everytime I try to run /usr/bin/php5 /path/to/phpscript.php, it fails to delete sth and gives me permission denied error:
rm: cannot remove `/path/to/sth': Permission denied
How can I make it work? I tried to change the ownership of phpscript.php to that of sth, but it didn't work.
5 Replies
> Did you try adding sudo before rm?
Wouldn't that be prompting you for password? The rm command is executed in a php script via exec(). I don't know if I can do that.
> Who's executing the script? Does that person have rights to remove that directory?
So the person who's executing the script should have the permissions to delete the thing rather than the owner of the script?
So www-data should be the person who executes the script instead of me (myuser)?
@mwalling:
Who's executing the script? Does that person have rights to remove that directory?
That's a great insight. I've added a crontab entry for user www-data instead of my user myuser:
sudo crontab -e -u www-data
Will see if it works.