When i try to use *shell_exec(cmd)* or system(cmd) for a command like ping google.com then it works properly.

Code 1:Will work in PHP

<?php
echo shell_exec(ping google.com)
?>

But when i try executing the following code it returns a blank page.

Code 2: Will not work in PHP

<?php
echo shell_exec(ec2-describe-addresses --region us-west-2)
?>

Both the commands

1.ping google.com

2.ec2-describe-addresses --region us-west-2

Works in windows command prompt properly.

Can someone please guide me as in how can i run the second command in PHP?

PS:ec2-describe-addresses --region us-west-2 is a AWS EC2 command to Describing Elastic IP Addresses for Account http://aws.amazon.com/articles/Amazon-EC2/1346

有帮助吗?

解决方案

The issue was that PHP was running not as root user changing the user to root actually solved the problem. For those who wants to know how to Switch PHP user to ROOT. Just Follow the following steps.

Step 1: Open httpd.conf

Step 2: Search for User/Group

Step 3: Under it you will find

User (your default user name)

Group (your default group name)

Change it to root so that your file looks like this:-

User root

Group root

Step 4: Restart Apache

PS:Switching PHP to work as root user is not suggested for production servers. Please change this only if you are sure about this.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top