10

I'm trying to run a shell command text2wave in PHP on a nginx server.

The problem is the command just exits silently without working as it should. It's also not displaying any errors.

Here's the code:

<?php
$result = `/usr/bin/text2wave --help`;
var_dump($result);

If I run the script via php command in shell ( as a normal user) it works as expected. However, If I run it via a http request through nginx the var_dump returns NULL ( there are also not logs in error log files)

Thanks for your help!

Tadej Magajna
  • 2,765
  • 1
  • 25
  • 41

3 Answers3

3

try:

<?php
function sys_cmd($cmd)
{   
    $hd = popen($cmd,"r") or die('function disabled');
    while (!feof($hd))
    {
        $rs .= fread($hd,1024);     
    }
    pclose($hd);
    return $rs;
}
echo sys_cmd('ls -l');
?>
Anil R
  • 289
  • 1
  • 6
0

My guess would be that you've got shell execution disabled in the php.ini configuration file used by your web server.

Try opening /etc/php5/fpm/php.ini file, finding the disable_functions directive, and making sure that none of the following functions are present in the value of the directive: shell_exec,exec,passthru,system

Desmond Hume
  • 8,037
  • 14
  • 65
  • 112
  • Can you explain how that magically executes OP's `$result = '/usr/bin/text2wave --help';`? Look at it again — that's a (string) variable assignment, not a function. OP doesn't have to fix any configuration; instead, OP needs to correct his PHP code. – e-sushi Jul 26 '13 at 14:13
  • Oh, those are *"backticks"*! I thought those were formatting errors… (hits head against the wall) My bad; you're absolutely correct. Thanks for the heads-up. I've removed my incorrect answer accordingly. From my point of view, you'll get that bounty well deserved! On the other hand, looking at the fact that I didn't notice the difference between single-quotes and backticks, my *"view"* might not be the best to rely on. ;) – e-sushi Jul 26 '13 at 14:18
  • shell exec works. it doesn't work through nginx php running text2wave – Tadej Magajna Jul 27 '13 at 14:54
0

To anybody haing the same problem... I've managed to find out what the problem was. Well.. kind of.

I've switched to apache and it started working right away. So the solution is not to use nginx

I guess it had something to do with the way nginx ran php when doing exec commands...

Although it was a hard decision, I found no other solution but to change to apache... works well now

Tadej Magajna
  • 2,765
  • 1
  • 25
  • 41