Rsync works from CLI but not PHP script

General support questions
edlentz
Posts: 71
Joined: 2013/06/11 20:20:25

Rsync works from CLI but not PHP script

Postby edlentz » 2018/03/29 20:26:34

So i have a rsync over ssh setup from one system to another using ssh keys so I can run it without needing to use passwords.

Here is the rsync command

Code: Select all

rsync -avzhe ssh /var/spool/asterisk/backup/ RcyEJtB2@xxx.xxx.xxx.xxx:/home/SystemBackups/backup


I can run this all day long from the command line and the host machine has the files uploaded to it. I have a php script that I want to use. But when I run it I get an error in the http error log:

Code: Select all

Host key verification failed.
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]


Here is the php code

Code: Select all

$backup = 'rsync -avzhe ssh /var/spool/asterisk/backup/ RcyEJtB2@xxx.xxx.xxx.xxx:/home/SystemBackups/backup';
shell_exec ($backup);


I have the permissions of the php file set to root:root 0777

How is this happening? The host key hasn't changed at all.

Any ideas greatly appreciated

Whoever
Posts: 1004
Joined: 2013/09/06 03:12:10

Re: Rsync works from CLI but not PHP script

Postby Whoever » 2018/03/30 02:27:08

Most likely, it's an SELINUX issue.

Try this:

Code: Select all

setsebool -P httpd_can_network_connect on


You can see the other SELinux booleans with:

Code: Select all

getsebool -a

edlentz
Posts: 71
Joined: 2013/06/11 20:20:25

Re: Rsync works from CLI but not PHP script

Postby edlentz » 2018/03/31 12:40:41

Thanks I will check that out

pjsr2
Posts: 307
Joined: 2014/03/27 20:11:07

Re: Rsync works from CLI but not PHP script

Postby pjsr2 » 2018/04/02 16:37:14

I have the permissions of the php file set to root:root 0777

Never give an executable program file write-permissions for "other". You have just created a major security hole in your system.

And unless you have a very good understanding of system security, you should not give "other" write permissions to a non-executable file or to a directory either.

pjsr2
Posts: 307
Joined: 2014/03/27 20:11:07

Re: Rsync works from CLI but not PHP script

Postby pjsr2 » 2018/04/02 16:43:42

But when I run it I get an error in the http error log:

The http web server is run as the special user "apache". This user has restricted permissions to run applications and is most likely not the same user as you use when you run this script from the command line.