远程服务器上的 exec() 仅返回 return-var 1 |7种方法尝试但没有成功


exec() on remote server returns only return-var 1 | 7 ways tried without success

在远程 apache 上(首先PHP Version 5.3.29 | 终于在没有启用安全模式的情况下更新到 7.04)我尝试运行一个微小的 20 个字符的 c 文件"ccc"

 exec(), popen(), shell_exec(), system(), passthru(), backtick

。其中 6 种方法中有 5 种在本地成功,到目前为止 6 种方法中有 0 种是远程方法。

我在 6 种情况中的 3 种情况下得到一个返回值"1"(passthru, exec, system ),以及一个带有 popen 的空 (?) 流(如果可能的话)(见下文)。

exec(), passthru(), system()愿意在远程服务器上运行像 ls 这样的命令,但 ccc 没有给我任何东西,c-testfile 中只有 printf("c did"); 个)。

服务器在升级到没有安全模式的php-Version 7.04后进行配置 (php-ini)。

我的文件可执行文件.php只尝试以 6 种方式运行 ccc(下面缩短)

// start source
error_reporting(E_ALL); 
echo exec ('ls', $out0, $error0);
$popen = popen ($cpath.'ccc', 'r'); 
stream_get_contents ( $popen ); 
shell_exec ($cpath.'ccc');
passthru ($cpath.'ccc', $error3);
exec ($cpath.'ccc', $out4, $error4);
system ($cpath.'ccc', $error5);
$output = `$cpath.ccc`; 
echo '20160316 errors 0-6 | 0: '.$error0.' |  3: '.$error3.' | 4: '.$error4.' | 5: '.$error5.'<br/>';   
echo '20160316 outputs 0-6 | 0: '.gettype($out0).' | 1: '.get_resource_type($popen).' | 4: '.gettype($out4).';  
// end source

该文件确实在本地服务器上打开了 c 文件而没有错误,但没有输出,在远程服务器上返回 1。

听起来 C 程序只是本地的。该程序必须位于远程服务器上。此外,apache 服务必须具有读取和执行权限。

将 php 版本升级到 5.4 以上的级别可能是一个答案。然后应该打开安全模式。也就是说,exec(), popen(), shell_exec(), system(), passthru() 不应该再被 php-ini-restrictions 阻止了。

问题是 c 文件,这不是该主机提供的功能。如果将可执行文件的给定路径($cpath)更改为exec(pwd)获得的路径,并将c-file类型更改为perl-file类型,并从目录中删除.htaccess,则执行是正确的。

相关文章: