Heim > php教程 > php手册 > Hauptteil

PHP调用Linux命令权限不足问题解决方法,phplinux

WBOY
Freigeben: 2016-06-13 09:15:28
Original
1151 Leute haben es durchsucht

PHP调用Linux命令权限不足问题解决方法,phplinux

业务背景:  yourcmd为我的linux程序,它对权限要求非常严格,当用php去执行yourcmd程序

系统:CentOS 6.3

apache是php的执行用户

用exec函数去执行linux系统上的程序/usr/local/yourcmd/sbin/yourcmd

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 )

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!