Rclone functioning via Debian CLI, but not through PHP exec()

As mentioned in the title, this isn't a rclone issue, it's just my inability to implement. Apologies if you fine folks would prefer me to seek guidance on S/O or somewhere, but I hoped not having to explain the platform would aid in ability to get advice.

My config is: v1.52.0-linux-amd64 / Debian x64 / Google Drive.

/nfs/c10/h10/mnt/228932/domains/fitaf570.com/html/lib/rclone copy /nfs/c10/h10/mnt/228932/domains/fitaf570.com/html/doc "gd:/lance/Fit AF/"
[gd]
type = drive
client_id = 1069064026498-d8hlv3qc6fbu7ivlhm1qm9qir9rd8tcm.apps.googleusercontent.com
client_secret = **************************
scope = drive
token = {"access_token":"ya29.a0AfH6SMCijFNcoBGTxYr38jYtS1Ng33W812v4mCdl_-9Yeo4RRWqS26JdAFQPOZVoJDupsJR0hjxHUG0OL2ITtt8NswmGMnTnO546JzORFxnXRycIZv_TTSDokoR-zRspxQnKF8swdZy2FckAPGiBaB-1HSiog4W0wW0","token_type":"Bearer","refresh_token":"1//0fbc7_q7ojHCrCgYIARAAGA8SNwF-L9IrmzlV-PavWDi7hyVEGE9NRTNKGRIRISvKMYsfFkpnvWEZc5O6TQDyiPHoAdIAIQrlCG8","expiry":"2020-06-10T19:19:38.99015576-07:00"}
root_folder_id = 0AAjs66ABvu2ZUk9PVA

Since the expected result occurs from CLI, I've elected not to include a log. I'm just hoping that someone has experience reproducing the functionality inside a PHP script and can offer guidance. I'm relatively inexperienced with exec() and just began using rclone today, but from what I can tell from digging around is that it should work considering as I've set the permissions to 777.

fitaf570.com@n17:/nfs/c10/h10/mnt/228932/domains/fitaf570.com/html/lib$ ls -la
-rwxrwxrwx  1 fitaf570.com fitaf570.com 39821312 Jun 10 18:38 rclone

I've tried various permutations of exec() shell_exec(), prefixing the command with "/bin/bash" or "sh" and nothing works. The closest I can get is a return error code of 126 Command invoked cannot execute

Being on shared hosting, I am somewhat limited in what I can accomplish. Certainly no sudo. Any advice greatly appreciated. This platform is very promising and exactly what I need to improve my company's process flow.

I still don't understand what exactly the problem.
Can explicitly share what is the problem and what are you trying to do?

I'm not sure I correctly understood your exact use case, but perhaps this explains what you are seeing?

exec is almost always turned off by shared hosts because it represents a security risk to both you and them.

(https://stackoverflow.com/questions/21127572/web-hosts-allowing-php-function-exec)

The problem is that the same command which is running fine on the CLI will not run in PHP's exec() function. It is likely operator error on my part, however, my host has confirmed that exec() is usable despite being on shared hosting.

Run this and post the output:

<?php

var_dump(exec('/nfs/c10/h10/mnt/228932/domains/fitaf570.com/html/lib/rclone -V 2>&1'));

A long shot but it might be permissions on the binary. Does the PHP script run as a different user? If so then chmod 755 the rclone binary and make sure that the directory it is in and its parents are all readable by the PHP user .

string(79) " runtime/asm_amd64.s:214 +0x125 fp=0x7ffd973fa6f8 sp=0x7ffd973fa6f0 pc=0x4655e5"

@ncw - Yes, PHP runs as a separate user, however, both the binary and the parent folders are set to be readabe by all. Modifying rclone to 755 from 777 produces no change in results.

This string looks like rclone is crashing. Can you get the whole output? It is very difficult to work out what is going on just from that string.

I'm not entirely sure how to achieve any more output.

exec ( string $command [, array &$output [, int &$return_var ]] ) : string

$output is an empty array, $return_var is merely the error code of 126 and no string is returned when I throw an echo before the exec() call.

So I'm not sure exactly what the "-V 2>&1" params do at the end of the debug suggested by Harry do. Are there other flags I could add to create more verbose output?

Where did you get that output?

It might be worth looking in the php logs or the web server logs they often catch standard error.

You could try adding -vv and --log-file /path/to/log but I feel rclone might not be getting that far.

I got that output from Harry's suggestion. I will try -vv this afternoon instead of -V

If a command is found but is not executable, the return status is 126
So, basically PHP don't have sufficient permission to execute rclone or Rclone isn't executable at all.
I suggest you to contact your hosting provider.

you can probably redirect to a OS file instead:
var_dump(exec('/nfs/c10/h10/mnt/228932/domains/fitaf570.com/html/lib/rclone -V 2>&1 > /tmp/file'));

but it just doesn't look like execute permission is there (or getting blocked)

If I have it set to 755, that means owner, group and everyone else have execute permission as well as read, correct? So why would whatever "user" php falls under be disqualified from execution?

I did reach out to my host and they said that this is beyond their usual level of support.

This produced an empty file, length 0.

Adding flags -vv --log-file was, as you suspected, @ncw , no change.

What does the mount for that nfs share look like?

mount | grep /nfs

10.10.0.6:/export/home on /nfs/c10/home/mnt type nfs (ro,noatime,nodiratime,vers                                                                                                                                                             =3,rsize=32768,wsize=32768,namlen=255,acregmin=30,acregmax=30,acdirmax=30,hard,n                                                                                                                                                             octo,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=10.10.0.6,mountvers=3,mount                                                                                                                                                             port=57964,mountproto=tcp,local_lock=none,addr=10.10.0.6)
tmpfs on /nfs/c10/home/mnt/default type tmpfs (rw,relatime,size=5120k,mode=755)
10.10.0.215:/frontend0/c10/h05 on /nfs/c10/h05/mnt type nfs (rw,noatime,nodirati                                                                                                                                                             me,vers=3,rsize=32768,wsize=32768,namlen=255,acregmin=25,hard,nolock,proto=tcp,t                                                                                                                                                             imeo=600,retrans=2,sec=sys,mountaddr=10.10.0.215,mountvers=3,mountport=64186,mou                                                                                                                                                             ntproto=tcp,local_lock=all,addr=10.10.0.215)
10.10.0.215:/frontend0/c10/h06 on /nfs/c10/h06/mnt type nfs (rw,noatime,nodirati                                                                                                                                                             me,vers=3,rsize=32768,wsize=32768,namlen=255,acregmin=25,hard,nolock,proto=tcp,t                                                                                                                                                             imeo=600,retrans=2,sec=sys,mountaddr=10.10.0.215,mountvers=3,mountport=64186,mou                                                                                                                                                             ntproto=tcp,local_lock=all,addr=10.10.0.215)
10.10.0.215:/frontend0/c10/h07 on /nfs/c10/h07/mnt type nfs (rw,noatime,nodirati                                                                                                                                                             me,vers=3,rsize=32768,wsize=32768,namlen=255,acregmin=25,hard,nolock,proto=tcp,t                                                                                                                                                             imeo=600,retrans=2,sec=sys,mountaddr=10.10.0.215,mountvers=3,mountport=64186,mou                                                                                                                                                             ntproto=tcp,local_lock=all,addr=10.10.0.215)
10.10.0.215:/frontend0/c10/h08 on /nfs/c10/h08/mnt type nfs (rw,noatime,nodirati                                                                                                                                                             me,vers=3,rsize=32768,wsize=32768,namlen=255,acregmin=25,hard,nolock,proto=tcp,t                                                                                                                                                             imeo=600,retrans=2,sec=sys,mountaddr=10.10.0.215,mountvers=3,mountport=64186,mou                                                                                                                                                             ntproto=tcp,local_lock=all,addr=10.10.0.215)
10.10.0.216:/frontend1/c10/h09 on /nfs/c10/h09/mnt type nfs (rw,noatime,nodirati                                                                                                                                                             me,vers=3,rsize=32768,wsize=32768,namlen=255,acregmin=25,hard,nolock,proto=tcp,t                                                                                                                                                             imeo=600,retrans=2,sec=sys,mountaddr=10.10.0.216,mountvers=3,mountport=49887,mou                                                                                                                                                             ntproto=tcp,local_lock=all,addr=10.10.0.216)
10.10.0.216:/frontend1/c10/h10 on /nfs/c10/h10/mnt type nfs (rw,noatime,nodirati                                                                                                                                                             me,vers=3,rsize=32768,wsize=32768,namlen=255,acregmin=25,hard,nolock,proto=tcp,t                                                                                                                                                             imeo=600,retrans=2,sec=sys,mountaddr=10.10.0.216,mountvers=3,mountport=49887,mou                                                                                                                                                             ntproto=tcp,local_lock=all,addr=10.10.0.216)
10.10.0.216:/frontend1/c10/h11 on /nfs/c10/h11/mnt type nfs (rw,noatime,nodirati                                                                                                                                                             me,vers=3,rsize=32768,wsize=32768,namlen=255,acregmin=25,hard,nolock,proto=tcp,t                                                                                                                                                             imeo=600,retrans=2,sec=sys,mountaddr=10.10.0.216,mountvers=3,mountport=49887,mou                                                                                                                                                             ntproto=tcp,local_lock=all,addr=10.10.0.216)
10.10.0.216:/frontend1/c10/h12 on /nfs/c10/h12/mnt type nfs (rw,noatime,nodirati                                                                                                                                                             me,vers=3,rsize=32768,wsize=32768,namlen=255,acregmin=25,hard,nolock,proto=tcp,t                                                                                                                                                             imeo=600,retrans=2,sec=sys,mountaddr=10.10.0.216,mountvers=3,mountport=49887,mou                                                                                                                                                             ntproto=tcp,local_lock=all,addr=10.10.0.216)
tmpfs on /nfs/c10/h01 type tmpfs (rw,relatime,size=1024k,mode=755)
tmpfs on /nfs/c10/h02 type tmpfs (rw,relatime,size=1024k,mode=755)
tmpfs on /nfs/c10/h03 type tmpfs (rw,relatime,size=1024k,mode=755)
tmpfs on /nfs/c10/h04 type tmpfs (rw,relatime,size=1024k,mode=755)

It was cut off...

mount /nfs/c10/h10/mnt

Or you can just look in the /etc/fstab. I want to see if they have any user or noexec in their mount.

and when you execute this exactly like this on the terminal, it works with the full path?

/nfs/c10/h10/mnt/228932/domains/fitaf570.com/html/lib/rclone -V

I don't think he has SSH access because he is using shared hosting.

I do have SSH access. This is where I am able to use rclone from...

@calisro

fitaf570.com@n17:~$ /nfs/c10/h10/mnt/228932/domains/fitaf570.com/html/lib/rclone -V
rclone v1.52.0
- os/arch: linux/amd64
- go version: go1.14.3
fitaf570.com@n17:~$ mount /nfs/c10/h10/mnt
mount: can't find /nfs/c10/h10/mnt in /etc/fstab
fitaf570.com@n17:~$ ls /etc/fstab
/etc/fstab
fitaf570.com@n17:~$ cd /etc/fstab
-bash: cd: /etc/fstab: Not a directory
fitaf570.com@n17:~$

/etc/fstab is a file:

cat /etc/fstab

I'm trying to see what options were used on that /nfs mount. The paste above was cut off.

cat /proc/mounts

Can you put rclone elsewhere? not on the nfs? and try it through php? in your regular home directory or in /tmp (although that could be mounted 'noexec'). The best info is really going to come from the provider though since this is shared.