Udit Gupta
Udit Gupta

Reputation: 3272

echo exec working but exec not

I am using red hat enterprise edition n try making a simple php page..

When I try with ...

 // html code
 <?php
 echo exec(<cmd>); 
 ?>
// rest html code

Its working fine

but when tried with ...

 // html code     
 <?php
 exec(<cmd>);
 ?>
 // rest html code

Its not working

even a simple command like cat,ls,etc not working and also I tried 2 > &1 then no error is printed .

What could be the possible error ???

Upvotes: 1

Views: 13339

Answers (2)

Phill Pafford
Phill Pafford

Reputation: 85318

Docs:

return a response from the command, you would need to print the response out as well

Example:

<?php
$response = array();
exec('whoami', $response);
print_r($response,true);
?>

Upvotes: 5

Udit Gupta
Udit Gupta

Reputation: 3272

okkkkkkk ......... I solved the problem. Actually there were two issues ...

  1. The apache user searches its command in /usr/bin folder by default and the command I was trying to use was located in /usr/local/bin. So I need to create a soft link of that command in the /usr/bin directory.

  2. Secondly , apache is a less privilaged user than root so need to on the sticky bit of command so that apache could successfully run the command.

I hope this will help someone else also who will face the same problem in future.

Upvotes: 0

Related Questions