1
votes

I installed aws cli on my local Ubuntu 18.04 development machine. It works fine from the terminal for example if i type:

$which aws I get: /usr/local/bin/aws. However, if i try to run this command from within a php script it does nothing.

$cmd ="aws --version";

try {
    $exec = exec($cmd,$output, $return);
    $exec2 = shell_exec($cmd);
}
catch(Exception $e)
{
    echo 'Message: ' .$e->getMessage();
}

exec2 returns null exec returns 127.

Now I understand that this is a paths issue and I have tried to add it to the path but it does not work.

I know this can be done using the php sdk but for various reasons i cant use that.

Can someone explain how to get this working on ubuntu 18.04 with php?

1
You didn't show us any error, we cannot help you if you don't provide some info. Are you sure it does nothing? Neither of those commands would show any output and you're not printing anything from $exec2 or $output. - Rikudou_Sennin
exec2 is null exec does returns 127 - user794846
looks like it was working all along i had redirect stdout to stderr using 2>&1 at the end of the command. - user794846

1 Answers

3
votes

My code was working all along. The issue was that I had to redirect stdout to stderr using 2>&1 at the end of the command.

 $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);