sh:从Web浏览器找不到php命令错误

问题描述:

I have one file with code

 shell_exec (php test.php)

When I run this file from command prompt, It run successfully and when same file I am trying to run through web browser this will give error as

 sh: php command not found.

what can be the issue?

我有一个带代码的文件 p>

  shell_exec(php test)  .php)
  code>  pre> 
 
 

当我从命令提示符运行此文件时,它运行成功,当我尝试通过Web浏览器运行相同的文件时,这将给出错误

  sh:找不到php命令。
  code>  pre> 
 
 

可能出现什么问题? p>

Problem was with php path. so I have done like this

 if(defined('PHP_BINARY') && PHP_BINARY) 
  {
    $path = PHP_BINARY . '/php'; //PHP >= 5.4
  }
 else if(defined('PHP_BINDER') && PHP_BINDER)
  {
    $path = PHP_BINDER . '/php'; //PHP < 5.4
  }
else
  {
    //Throws Exception 
  }

and then used this variable in shell command as

   shell_exec ($path test.php)  

could you please provide the information which webserver you're using ? If you are using apache you might install libapache2-mod-php7.0 for php7.

ToDo this apt comes in handy:

apt-get install libapache2-mod-php7.0

or try to activate it

sudo a2enmod php7.0

Make sure that the php files are marked executable for webserver user (e.g. www-data)

sudo chmod -R o+x *.php