1

I am using shell_exec command to get the back end processes of PHP. Like:

$dir = shell_exec("ls -la");  //returns directory listing
$date = shell_exec("date");  //returns date
$pid = shell_exec("pidof php"); //returns nothing !!!

If I run "pidof php" from command console as root, it gives me the correct result. I'm using PHP 5.5 and CentOS 6.5.

What additionally I need to do to get the processes?

N.B: If I run the file from command line, it gives me the correct result. But the same file when running from browser, can't return the processes.

user2432443
  • 147
  • 2
  • 11
  • Does `pgrep -f php` work instead of `pidof php`? – Eric Renouf Oct 18 '15 at 13:43
  • No, your command works from the terminal, but not from php file – user2432443 Oct 19 '15 at 11:12
  • Try this answer: http://unix.stackexchange.com/a/127529/109842 which suggests adding permission in `sudoers` to the web server user to run `pidof` – Eric Renouf Oct 19 '15 at 13:04
  • Thank for your answer, anyway my problem is solved, I have disabled the SElinux in my system. Now, I get what I want, but not sure about the impact of disabling it – user2432443 Oct 19 '15 at 13:08
  • Ok, you might want to consider a more "surgical" approach as well, like perhaps one similar to http://stackoverflow.com/questions/15395845/tell-selinux-to-give-apache-execute-access-to-php-files-outside-document-root – Eric Renouf Oct 19 '15 at 13:14

0 Answers0