0

For some reason, the following php script when called via apache, is not returning results... is there a system security setting in php.ini somewhere to allow system commands?

<div style="background:#000;color:#fff">
<?php

   $cmd = "/bin/date";
   $output = system($cmd);
   printf("System Output: $output\n");
   exec($cmd, $results);
   printf("Exec Output: {$results[0]}\n");
   echo"<pre>";
   echo system('/bin/ls');
   echo"</pre>";
   ?>
   </div>
hakre
  • 193,403
  • 52
  • 435
  • 836
Cmag
  • 14,946
  • 25
  • 89
  • 140
  • I have checked php.ini, disable_functions= is blank. – Cmag Sep 29 '11 at 17:05
  • What is returning nothing? `system´ or `exec` or both? – hakre Sep 29 '11 at 17:09
  • neither..... Also system is on plesk... :) – Cmag Sep 29 '11 at 17:25
  • You should first look into similar questions like yours (see the Realated column on the right and on top there is a search box). There can be numerous reasons why these commands "do not work" (in fact they work, but they don't do what you expect - but they work fine!). Also think about how you can debug your problem (your code looks like you started debugging already). Additionally, contact your system administrator, she/he should be able to help you as well. And enable error reporting with PHP, there is safe-mode and such. – hakre Sep 29 '11 at 17:27
  • it appears safe mode is on... via phpinfo.php. Does anyone know how to turn off safe mode in plesk? in php.ini it says safe mode off ... – Cmag Sep 29 '11 at 17:29
  • Please learn about the basics of PHP configuration, e.g. see: http://php.net/manual/en/configuration.php - Please see as well: [PHP: exec() error responses?](http://stackoverflow.com/questions/345794/php-exec-error-responses) – hakre Sep 29 '11 at 17:35

2 Answers2

1

Your host (or configuration) is probably restricting system() or exec() command. Check your configuration or contact your host

; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
; http://php.net/disable-functions
disable_functions =

should be blank, works on my machine

http://sandbox.phpcode.eu/g/e47f7

Also, check that SElinux and Suhoshin is configured properly

genesis
  • 50,477
  • 20
  • 96
  • 125
  • guys, selinux is disabled... how come is this happening? – Cmag Sep 29 '11 at 17:22
  • also seeing sh: /date: No such file or directory sh: /date: No such file or directory sh: /ls: No such file or directory in apache logs – Cmag Sep 29 '11 at 17:28
0

plesk safe mode... disabled in httpd.include... sigh... love it when systems land in your lap

Cmag
  • 14,946
  • 25
  • 89
  • 140