我在我当地的Ubuntu 18.04开发机器上安装了aws cli。它可以从终端正常工作,例如,如果我输入:
$which aws
我得到:/usr/local/bin/aws
。但是,如果我尝试从php脚本中运行此命令,它什么都不做。
$cmd ="aws --version";
try {
$exec = exec($cmd,$output, $return);
$exec2 = shell_exec($cmd);
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
exec2
返回null exec返回127。
现在我明白这是一个路径问题,我试图将它添加到路径但它不起作用。
我知道这可以使用php sdk完成但由于各种原因我不能使用它。
有人可以解释如何使用php在ubuntu 18.04上运行吗?
我的代码一直在努力。问题是我必须在命令末尾使用2>&1将stdout重定向到stderr。
$cmd = "aws redshift restore-table-from-cluster-snapshot --cluster-identifier {$this->redshift_cluster_identifier} --snapshot-identifier {$this->snapshot_identifier} --source-database-name citnow --source-table-name {$tableName} --target-database-name citnow --new-table-name {$newTableName} 2>&1";
$exec = exec($cmd,$output, $return);