PHP cp permissions issue
PHP Script (restore.php):
var_dump( get_current_user());
var_dump( shell_exec( " cp /var/www/bkp/* /var/www/html 2>&1 " ));
When script is accessed in browser:
string(6) "apache"
string(115) "cp: cannot create 开发者_如何学Cregular file `/var/www/html/227.png': Permission denied cp: cannot remove `/var/www/html/234.png' Permission denied "
Console:
cd /var/www/html
sudo -u apache touch test.txt
ls test.txt
-> test.txt
sudo -u rm 234.png -f
ls 234.png
-> ls: 234.png: No such file or directory
sudo -u apache php restore.php
ls 234.png
-> 234.png
Can anyone explain why I am getting permission issues in my php script when run in browser?
Are you sure that Apache is running as the apache
user? get_current_user()
returns the owner of the script. You would think Apache would be running as apache
but maybe it's not.
You can get the name of the process owner with this:
$processUser = posix_getpwuid(posix_geteuid());
print $processUser['name'];
check that /var/www/ owner is www-data( the user of apache web server ),and he have the permission to red & write .
精彩评论