PHP調用Linux命令權限不足問題解決方法
更新時間:2015年02月07日 16:48:04 投稿:junjie
這篇文章主要介紹了PHP調用Linux命令權限不足問題解決方法,本文是解決項目問題總結而來,通過修改sudo配置文件解決無權限執(zhí)行命令問題,需要的朋友可以參考下
業(yè)務背景: yourcmd為我的linux程序,它對權限要求非常嚴格,當用php去執(zhí)行yourcmd程序
系統(tǒng):CentOS 6.3
apache是php的執(zhí)行用戶
用exec函數去執(zhí)行l(wèi)inux系統(tǒng)上的程序/usr/local/yourcmd/sbin/yourcmd
php代碼如下:
復制代碼 代碼如下:
<?php
$conf_file = "/var/www/html/webroot/test.tmp";
$command = "sudo /usr/local/yourcmd/sbin/yourcmd -t -f {$conf_file}";
exec($command,$out);
print_r($out);
測試結果為沒有權限
復制代碼 代碼如下:
Array ( [0] => sudo: no tty present and no askpass program specified )
解決步驟:
復制代碼 代碼如下:
$ visudo
1)注釋以下行
復制代碼 代碼如下:
#Defaults requiretty
2)在文件末尾加入以下
復制代碼 代碼如下:
apache ALL=(ALL) NOPASSWD: ALL
Cmnd_Alias yourcmd = /usr/local/yourcmd/sbin/yourcmd
最后測試結果
復制代碼 代碼如下:
Array ( [0] => Warning: memory is too small: 1044725760 [1] => test configure is ok )
相關文章
基于ThinkPHP+uploadify+upload+PHPExcel 無刷新導入數據
這篇文章主要介紹了基于ThinkPHP+uploadify+upload+PHPExcel 無刷新導入數據的相關資料,需要的朋友可以參考下2015-09-09

