简体   繁体   中英

php exec() rsync ssh to remote server not working

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?

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). ie 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM