I am working on a web server running on Apache in Linux. I am trying to use the system()
call from PHP to use the Amazon EC2 Command Line tools (ec2-describe-instance
,etc). However, it doesn't work. Webpage doesn't show the result (other commands like echo
work fine).
My PHP code looks like:
<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");
?>
I've tried using the Apache user to try the command, and this is what I get:
[ec2-user@ip-xx-xxx-xx-xxx ec2testing]$ sudo su apache
bash-4.1$ ec2-describe-addresses
bash: ec2-describe-addresses: command not found
The commands seem not to be 'installed' for the Apache user.
I've tried using the method described in this blog post, but it still doesn't work.
Is there something I'm missing?
EDIT: Using this:
echo exec("echo 'testing'; sudo ec2-describe-addresses -O (Access Key Removed) -W (Secret Key Removed)");
gives me this:
bash-4.1$ php index.php
<h1>Beginning System Call</h1>
php started</br>[sudo] password for apache:
Best Answer
Add the whole path in your script: