I have a problem where I am trying to copy a file that is generated on a server drive that I have mounted using the php exec command. However, the command doesn't work (although the return status is 1) when called from a web-page.
$src = "/mnt/...";
$dest = "/var/www/...";
exec("cp $src $dest");
I have tried printing out the command to make sure it is correct, and it is. I have also tried making sure the file exists before attempting to copy it and it is.
if (file_exists($src)) {
exec("cp $src $dest");
}
Copying the command directly into the terminal works.
$ >cp /mnt/... /var/www/...
I've also tried using the php command line tool to run the exec command and that also works.
$ >php -r 'exec("cp /mnt/... /var/www/...");'
I have also tried using shell_exec
as well, with the same results.
is_writable($dest)
. Chances are it'sfalse
, which means, as others have said, the PHP user cannot write to it. Usually PHP is ran as theapache
(www-data
) ornobody
user. Runecho exec("whoami");
to see the user it's running as. – Rocket Hazmat Aug 27 at 18:44