My script creates a directory. Before I realized that I needed to chown() the directory from apache to my user name so that I could access the uploaded files, I ran the script a few times. Now I can’t seem to get rid of the directory so I can start clean.
I figured that all I needed to do was write a PHP script to do is since within the script I would ‘be’ apache. I’ve tried rmdir and chown but I keep getting permission denied. I even tried loading the file in browser instead of just php file.php at the command line in case that affects the effective user.
What else can I try?
I already realized invoking the script from the command line would run it with my username as the user instead of the username that the web server runs it as (apache) so I’ve been invoking the script through the browser. I’ve been simply trying to chown it to my user name so that I can delete it from the command line instead of trying to write some recursive rmdir function.
<?php
$target = "/some/absolute/file/path";
chown($target, "myself");
?>
This is a common problem on shared hosting, anyways there are several ways to fix that.
www-user” only when executed through the web server. If you run them from shell asphp script.php, they are executed as the user you are logged in with — let’s call it “shell-user“.www-userandshell-userhave a group in common (it depends on your shared hosting provider policies), you can justchgrpall the files/directories (recursively) to that group, change permissions on440for files,770for directories, and you will be able to manipulate them asshell-usertoo. Better way would be to use Posix ACLs to automatically set group/permissions, but it’s not common to find that enabled on shared hostings.sudotowww-user, so that you can run commands as that user too. If not, the only way is making it run php scripts through the webserver.If you just want to delete directory recursively..
..you can use a function like this (From: https://gist.github.com/1407308):
Just beware that you cannot change ownership on dirs/files from an unprivileged user, only group and permissions.