php exec() rsync ssh to remote server not working

喜夏-厌秋 提交于 2019-12-11 00:38:21

问题


I am trying to rsync file from local to remote server. When i do this on console it works:

rsync -avzhe ssh /var/www/folder1/file5 root@192.168.56.74:/var/www/folder2

but when i do this on my php and run the php script, it doesn't work:

$rysncCommand = "rsync -avzhe ssh /var/www/folder1/file5 root@192.168.56.74:/var/www/folder2";

shell_exec($rysncCommand);

There is no error shown, so i can't really tell what is the error. Is there something wrong with my php script?


回答1:


First, you need to check if you need to be a root or (sudo user) for running rsync.

If yes then exec() command will only work if it is run by same user on php-cli (not on browser by Apache user). i.e. Which user you are loggined into shell for run rsync.

If it is root or any elavated permission user with sudo permission then, This rsync command may not be available to apache/www-data user which is working when php script run from browser.

So You try to make a normal user and login through it, Then try rsync if you are successful then it may be interesting to see what are other problems can be, But if you getting access/permission denied then obviously you can not run this script at-least on browser.

Besides this One more thing permission may not be directly related to rsync command itself but with folder /etc/test/ which is owned by root user in normal scenario.

For more details you can check this Stack Overflow Link .



来源:https://stackoverflow.com/questions/30772816/php-exec-rsync-ssh-to-remote-server-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!