I have two machines, 192.168.10.6 (local machine) which has my php script and 192.168.12.163 (remote machine) which has my python script. How can I run this remote python script from a local PHP script?
I have a working code for running local python script from a local PHP script but I'm not able run remote Python script from a local PHP script.
I was about to propose using shell_exec
/exec
to spawn ssh and run a command on the remote host, for example:
$out = shell_exec('ssh user@192.168.12.163 "ls -la"');
However, I see that PHP supports that with ssh2_exec
, example:
$connection = ssh2_connect('192.168.12.163', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, 'python /path/to/script');
If ssh2 is not available on your server and you cannot install it, you can try phpseclib (see here for example)