1

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: 
6
  • 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. Commented Apr 3, 2013 at 18:50
  • @etagenklo See updated post Commented Apr 3, 2013 at 18:53
  • I still don't see a sudo in your php code. Commented Apr 3, 2013 at 18:55
  • @etagenklo You read too fast, and I don't type fast enough! It's edited now. Commented Apr 3, 2013 at 18:57
  • What exactly did you add to your /etc/sudoers file? Commented Apr 3, 2013 at 18:58

2 Answers 2

1

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)"); 
1
  • Thanks! Now just need to fix my EC2_HOME is not set thing. Should be easy. Commented Apr 3, 2013 at 19:13
0

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

4
  • Doesn't answer this question, but answered my next question! Thanks! Commented Apr 3, 2013 at 19:16
  • Which kind of child? Commented Apr 3, 2013 at 19:20
  • sorry for that , my intention is not heart you Commented Apr 3, 2013 at 19:24
  • Good Bro, keep it up... Commented Apr 3, 2013 at 19:27

You must log in to answer this question.