Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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");
?>

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
show 1 more comment

2 Answers

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
add comment

PATH variable is not set for ec2-describe-addresses

So you have two option

Option1

Set PATH by using

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

Option2

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
add comment

Your Answer

 
discard

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.