Home > php教程 > php手册 > body text

PHP调用Linux命令无权限的问题解决(visudo)

WBOY
Release: 2016-05-26 08:20:42
Original
1439 people have browsed it

下面来看一个关于PHP调用Linux命令无权限的问题解决(visudo),希望文章对大家有帮助.

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

系统:CentOS 6.3

apache是php的执行用户

用exec函数去执行linux系统上的程序/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);
Copy after login

测试结果为没有权限

Array ([0] => sudo: no tty present and no askpass program specified)

解决步骤:

$ visudo

1)注释以下行

#Defaults    requiretty
Copy after login

2)在文件末尾加入以下

apache ALL=(ALL) NOPASSWD: ALL
Cmnd_Alias yourcmd = /usr/local/yourcmd/sbin/yourcmd
Copy after login

最后测试结果:

Array ( [0] => Warning: memory is too small: 1044725760 [1] => test configure is ok )
Copy after login


文章链接:

随便收藏,请保留本文地址!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!