Apache运行命令行命令

我正在Linux上运行在Apache上的Web服务器上工作。 我正在尝试使用PHPsystem()调用来使用Amazon EC2命令行工具( ec2-describe-instance等)。 但是,它不起作用。 网页不显示结果(其他命令如echo工作正常)。 我的PHP代码如下所示:

 <h1>Beginning System Call</h1> <?php echo 'php started</br>'; echo exec("echo 'testing'; ec2-describe-addresses -O MY_AWS_ACCESS_KEY -W MY_AWS_SECRET_KEY"); ?> 

在这里输入图像说明

我已经尝试使用Apache用户来尝试命令,这就是我得到的:

 [ec2-user@ip-xx-xxx-xx-xxx ec2testing]$ sudo su apache bash-4.1$ ec2-describe-addresses bash: ec2-describe-addresses: command not found 

对于Apache用户来说,这些命令似乎不被“安装”。

我试过使用这个博客文章中描述的方法,但它仍然不起作用。

有什么我失踪?

编辑:使用这个:

 echo exec("echo 'testing'; sudo ec2-describe-addresses -O (Access Key Removed) -W (Secret Key Removed)"); 

给我这个:

 bash-4.1$ php index.php <h1>Beginning System Call</h1> php started</br>[sudo] password for apache: 

在脚本中添加整个path:

 echo exec("echo 'testing'; sudo /opt/aws/apitools/ec2/bin/ec2-describe-addresses -O (Access Key Removed) -W (Secret Key Removed)"); 

没有为ec2-describe-addresses设置PATHvariables

所以你有两个select

选项1

通过使用设置PATH

export PATH=$PATH:/opt/aws/apitools/ec2/bin/

选项2

使用abosolutepath运行命令即/opt/aws/apitools/ec2/bin/ec2-describe-addresses