通过SSH运行时,包含在远程脚本中失败

问题描述 投票:0回答:1

我在本地运行一个脚本,完成后对远程服务器上的脚本执行exec调用。

exec("ssh [email protected] \"php /full/path/to/script.php\"", $output, $return);

它向我提出了这个错误:

PHP Warning:  require(../resources/vendor/autoload.php): failed to open stream: No such file or directory in /full/path/to/script.php on line 3

我已经尝试将所需的脚本收费到它的完整路径但没有成功。有任何想法吗?

php ssh require
1个回答
0
投票

因为PHP将CWD(当前工作目录)设置为SSH登录后的位置(可能是用户主文件夹),并且PHP文件中对包含的引用被解释为相对于CWD。您应该将目录更改为项目的根目录:

exec("ssh [email protected] \"cd /full/path/to/; php script.php\"", $output, $return);
© www.soinside.com 2019 - 2024. All rights reserved.