3

I am running an SCO Unix box with apache version 1.3.33 and PHP version 4.4. I can properly execute the exec command through the cli, but run into trouble with trying to execute the script via a browser. My settings are:

  • safe mode off
  • full read/write/exec permissions
  • displaying all errors
  • no disabled functions

My code: test_script.php in htdocs dir

<?php
exec('ls',$out,$rval);
echo "Output:<hr />";
print "<pre>"; print_r($out); print "</pre>";
echo "Return Value:<hr />";
echo $rval;
?>

I've tried setting the executable binary path explicitly also. The test script is the same User/Group as apache. I've also tried adding 2>&1 to the arg, but see no change. Thank you in advance.

See here for similar.

Community
  • 1
  • 1
  • 1
    whats the output of your script? – AbiusX Mar 14 '11 at 23:40
  • @mario, Yes I have tried setting the path explicitly. –  Mar 14 '11 at 23:42
  • @AbiusX, the output in the browser is an empty array. Return value is 1. –  Mar 14 '11 at 23:43
  • 3
    Please be aware that the PHP developers themselves stopped supporting PHP4 literally years ago, and that Apache 1.3 is practically prehistoric. If you didn't already know you were in the stone age by using SCO Unix, then please let this be an appropriate notice. :) – Charles Mar 14 '11 at 23:51
  • Can you try [`proc_open`](http://us3.php.net/manual/en/function.proc-open.php) and see what happens? It's complex to use, but there's a pretty good example there in the docs that *should* work for you. – Charles Mar 14 '11 at 23:52
  • Try the backtick operator `commands here`, But i strongly suggest u update your box. I doubt anyone masters PHP 4 now! – AbiusX Mar 15 '11 at 00:19
  • Using SCO Unix is likely to get you sued if you so much as walk within 500 lightyears of a piece of paper that has the word "Linux" on it. – Marc B Mar 15 '11 at 01:23

2 Answers2

6

try

$output = shell_exec('ls /tmp/ 2>&1')

you might be having an issue with permissions to current directory for the user running the web page.

you can also try whoami command.

Shoshan
  • 311
  • 1
  • 4
0

Sometimes these functions are disabled, you have to enable them in php.ini

Teodoros
  • 311
  • 2
  • 12