I want to execute a git command in my php script. And this is my script demo.php.
<?php
exec("ssh -v > log1.txt 2>&1");
exec('git clone git@github.com:xxx/xxx.git >log.txt 2> &1',
$out,$ret);
?>
When I execute this:
php demo.php
It clones the target project. However, when I execute it through fpm by typing the url in the browser, it sends the request to nginx, then nginx transfer this request to fpm.
type url: localhost:port/demo.php
Now it comes into trouble and the output is as below:
log1.txt
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
[-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
[-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
[-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]
It seemed that this script executed by fpm and ssh has already been installed.
However log.txt is as below:
Cloning into '/home/geek/xxx/phpStudy/idl'...
error: cannot run ssh: No such file or directory
fatal: unable to fork
It seemed that it can't find the ssh command when executing git clone from this file.
I can do it with cli, and I can execute ssh command with fpm, but I cannot run ssh with git clone and fpm. This question has tortured me for serveral days. I will appreciate any advice.