0

I am trying to initiate an AWS instance through a bash script. This bash script is invoked by a PHP script.

My example php script:

<?php
exec("sh /var/www/html/pushDatToAWS.sh >> $trainLog");
?>

My example bash script:

#!/bin/bash
insId='i-abcde'
aws ec2 start-instances wait --instance-ids $insId --region us-west-2

I have configured aws cli on my machine. I am getting the following error.

/var/www/html/pushDatToAWS.sh: 21: /var/www/html/pushDatToAWS.sh: aws: not found

The file has 777 rights and when I try to execute from terminal everything works perfectly. When I check with which aws I get a response indicating /home/name/.local/bin/aws. I have the path exported to bashrc.

export AWS_PATH=$PATH:/home/magesh/.local/bin

I have tried hard coding the path to my aws start instance command:

/home/name/.local/bin/aws start-instances wait --instance-ids $insId --region us-west-2

For this I am getting permission denied error. I have tried changing the user ownership of the folder to root:www-data and username:www-data. Neither worked.

  • How is the php script being executed? – Jesse_b Dec 27 '18 at 19:37
  • It is possible (probable) that the php script has access to the shell script and directory it's located in but not every directory in between. You will need to ensure the permissions on /home, /home/magesh, /home/magesh/.local, and /home/magesh/.local/bin allow access to whatever user is executing the php script. – Jesse_b Dec 27 '18 at 19:40
  • @Jesse_b Thank you...I tried changing the ownership for the entire path uptill home to magesh:www-data ....however it didn't work. However, I used AWS SDK for PHP and configured based on examples given in AWS documentation...it worked...thank you again. – Apricot Dec 28 '18 at 2:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.