Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>
echo 'php started</br>'; 
echo exec("echo 'testing'; ec2-describe-addresses -O MY_AWS_ACCESS_KEY -W MY_AWS_SECRET_KEY");

enter image description here

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: 
share|improve this question
Read the blog post again. I don't see a sudo in your php script. Additionally: If your apache is reachable from the outside, you definitely shouldn't give it sudo permission. – etagenklo Apr 3 '13 at 18:50
@etagenklo See updated post – Undo Apr 3 '13 at 18:53
I still don't see a sudo in your php code. – etagenklo Apr 3 '13 at 18:55
@etagenklo You read too fast, and I don't type fast enough! It's edited now. – Undo Apr 3 '13 at 18:57
What exactly did you add to your /etc/sudoers file? – etagenklo Apr 3 '13 at 18:58
up vote 2 down vote accepted

Add the whole path in your script:

echo exec("echo 'testing'; sudo /opt/aws/apitools/ec2/bin/ec2-describe-addresses -O (Access Key Removed) -W (Secret Key Removed)");
share|improve this answer
Thanks! Now just need to fix my EC2_HOME is not set thing. Should be easy. – Undo Apr 3 '13 at 19:13

PATH variable is not set for ec2-describe-addresses

So you have two option


Set PATH by using

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


run command using abosolute path i.e /opt/aws/apitools/ec2/bin/ec2-describe-addresses

share|improve this answer
Doesn't answer this question, but answered my next question! Thanks! – Undo Apr 3 '13 at 19:16
Which kind of child? – Undo Apr 3 '13 at 19:20
sorry for that , my intention is not heart you – Rahul Patil Apr 3 '13 at 19:24
Good Bro, keep it up... – Rahul Patil Apr 3 '13 at 19:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.