2014-05-07 99 views
1

我無法在Apache上使用exec()在PHP中執行ifconfig。我可以執行所有類型的命令,包括ip addr list,但是那個會吸球,所以我真的需要能夠執行ifconfig。無法用php執行ifconfig

我已閱讀其他帖子,並確保disable_functions是=「」[空白],但仍然沒有運氣(我重新啓動apache)。這感覺就像是某種權限問題,因爲所有其他命令都可以正常工作。

在第一個文件我只是Exec,然後重新清理的結果,因爲我想它,我敢肯定這是不是問題出在哪裏,因爲它工作正常脫穎而出其他命令

第一文件

function execute($command){ 
    exec($command, $output); 

    $output_array;         // each row contains a array representing all elements in a output row 
    for ($i = 0; $i < sizeof($output); $i++){ 
    $tmp_array = explode(" ",$output[$i]);  
    $output_array[$i] = $tmp_array; 
} 
// clear the array from all "" 
    $clean_array;        
    for ($i = 0; $i < sizeof($output_array); $i++){ 
    $tmp; 
    $index = 0; 
    for ($j = 0; $j < sizeof($output_array[$i]); $j++){ 
     if (strlen($output_array[$i][$j]) > 0){ 
      $tmp[$index++] = $output_array[$i][$j]; 
     } 
    } 
    $clean_array[$i] = $tmp; 
    } 
    return $clean_array; 
秒文件

include "../app_includes/application_functions.php"; 
$command = "ifconfig"; 
//$command = "ip addr list"; 
$arr = execute($command); 
// print the result 
for ($i = 0; $i < sizeof($arr); $i++){ 
    for ($j = 0; $j < sizeof($arr[$i]); $j++){ 
     echo $arr[$i][$j]." "; 
    } 
    echo "<br>"; 
} 

解決: 這個問題是通過執行 「/ sbin目錄/的ifconfig」,而不是僅使用ifconfig解決

+0

我不知道,如果你不能在你的php.ini – OpenStark

+0

指定它,你可以調用使用ifconfig在EXEC我將如何在那裏添加它,即我應該寫什麼? –

+0

你試過在你的命令行中執行:su -u www-data -c/sbin/ifconfig?結果是什麼? – gafreax

回答

4

普通用戶不能在某些Gnu/Linux上使用ifconfig,但可以使用/ sbin/ifconfig。因此,嘗試這種

<?php 
$command="/sbin/ifconfig"; 
exec($command, $output); 
?> 

要確保有關的路徑,這帶在你的終端

whereis ifconfig 
+1

作品的最佳方式:D謝謝! –