Why this:
rsync -avz -e ssh /home/userneme/folder [email protected]:/var/www/folder
works from cronjob and this:
exec("rsync -avz -e ssh /home/userneme/folder [email protected]:/var/www/folder");
doesn't work.
I know exec is working because i have a few places in my appp that do convercion from pdf to jpg with ImageMagick (exec).
SOLVED
exec is working OK it was a permission issue on remote server. "Local" server is shared reseller account and remote server is my first VPS Ubuntu 10.10 LAMP box. If only I had a system administrator since i'm just a software developer forced to do this and i stink at it :) Thank You all!
This is probably PATH related. try execing rsync with a full path e.g.
Your ssh keys should be also on apache home folder. If not, the rsync will not work.
Regards
Does your host have
safe_mode
on?Run
php -i |grep -i safe
. If safe mode is on, then look atsafe_mode_exec_dir
. If rsync isn't in one of the listed folders, then PHP won't exec it.You can ask your host to put a symlink to rsync in the
exec_dir
path, and then exec it from that location; but it depends on their policy as to whether they'll allow it.You should be able to do this by giving ssh a specific key file to use in the
-e
option to rsync. Since you're using a shared host, what you need to do is create the ssh key somewhere safe, then put the keys onto the host in some directory as safe as you can get (should only be readable by you and apache, but if anyone else knows about it they can use a PHP script or something else to have apache send your key to them. If your host uses suexec for scripts so they all run under your username, you can make it readable only by you.)Then you would use
Since this isn't very secure, you should set up the remote side's authorized keys file to force a command that will, at the very minimum, verify that the command being executed is "rsync".
More on automating rsync (including a script to verify the ssh command) here.