0

I have EC2 tools installed under ubuntu user on a Amazon EC2 machine and my shell scripts make use of these tools to update code on various environments. Now we have PHP sitting on top of these shell scripts and I am using shell_exec to execute these shell scripts from the web but I get the following error:

home/ubuntu/ec2-tools/bin/ec2-describe-instances: line 9: EC2_HOME: EC2_HOME is not set

I believe this is happening because PHP executes scripts as www-data and EC2_HOME is defined for ubuntu user. echo $EC2_HOME give me the right path from the command line when logged in as Ubuntu.

Can any one please help me how to successfully execute the shell scripts using PHP.

Thanks

1 Answer 1

1

Why don't you either:

  • Use the php function putenv (http://php.net/manual/en/function.putenv.php) to set the environment variable EC2_HOME before using shell_exec.
  • Get the web server to set the EC2_HOME env variable. ("SetEnv" for apache, if using fastcgi and nginx then use "fastcgi_param EC2_HOME /somelocation")
Sign up to request clarification or add additional context in comments.

1 Comment

Using putenv function did solved the problem to environment variables. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.