开发者

PHP cp permissions issue

开发者 https://www.devze.com 2023-04-12 03:18 出处:网络
PHP Script (restore.php): var_dump( get_current_user()); var_dump( shell_exec( \" cp /var/www/bkp/* /var/www/html 2>&1 \" ));

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 .

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号