源代碼:

在網上也搜索了答案
比較詳細的答案是:
<?php
exec("lsof -i:80",$out,$status);
結果:
var_dump($out);
array(0) { }
echo $status;值為127
2、通過:shell_exec("id -a");查看一下用戶以及用戶組
<?php
echo shell_exec("id -a");
結果:uid=1002(www) gid=1002(www) groups=1002(www)
3、登錄Linux給www用戶賦予root級別的權限試一試看
修改/etc/sudoers檔案
root ALL=(ALL) ALL
下面增加一行
www ALL=(ALL) ALL
修改后執行php,結果沒意義,回傳的陣列依然為空array(0) { }
4、修改權限沒有效果,網上查詢說exec第三個引數回傳127可能還與路徑有關系,那么從路徑方面著手試一試
exec("whereis lsof", $out);
var_dump($out);
結果:
array(1) { [0]=> string(50) "lsof: /usr/sbin/lsof /usr/share/man/man8/lsof.8.gz" }
lsof命令所在檔案路徑: /usr/sbin/lsof
所以把 exec("lsof -i:80",$out1,$status);修改為exec("/usr/sbin/lsof -i:80",$out1,$status);
var_dump($out1);
結果成功執行了
回傳結果如下:
array(6) {
[0]=> string(56) "COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME"
[1]=> string(67) "nginx 31706 www 6u IPv4 165987 0t0 TCP *:http (LISTEN)"
[2]=> string(67) "nginx 31707 www 6u IPv4 165987 0t0 TCP *:http (LISTEN)"
[3]=> string(113) "nginx 31707 www 12u IPv4 232481 0t0 TCP localhost.localdomain:http->192.168.204.1:55893 (ESTABLISHED)"
[4]=> string(67) "nginx 31708 www 6u IPv4 165987 0t0 TCP *:http (LISTEN)"
[5]=> string(67) "nginx 31709 www 6u IPv4 165987 0t0 TCP *:http (LISTEN)"
}
_______________________________________________________________________________________________________
linux 配置情況:
php.ini 組態檔我沒有禁用exec()函式 安全模式 也是false
/etc/sudoers 檔案也配置了

結果依舊沒有生效 真的很悲劇啊
為此我做了個實驗

證明上面我的配置是正確的!!!!
系統的命令就不需要加全路徑 一般放在/usr/bin/ 下面的命令
但問題還是來了 which php 始侄訓傳不了值????????
exec("/usr/local/node/bin/node -v 2>&1", $out, $status); 只能換種方式了,這種方式比較的保守
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/83260.html
標籤:PHP
上一篇:centos通過yum安裝php
