这篇文章主要介绍了php调用linux命令权限不足问题解决方法,本文是解决项目问题总结而来,通过修改sudo配置文件解决无权限执行命令问题,需要的朋友可以参考下
业务背景: yourcmd为我的linux程序,它对权限要求非常严格,当用php去执行yourcmd程序
系统:CentOS 6.3
apache是php的执行用户
用exec函数去执行linux系统上的程序/usr/local/yourcmd/sbin/yourcmd
立即学习“PHP免费学习笔记(深入)”;
php代码如下:
代码如下:
测试结果为没有权限
代码如下:
Array ( [0] => sudo: no tty present and no askpass program specified )解决步骤:
代码如下:
$ visudo1)注释以下行
代码如下:
#Defaults requiretty2)在文件末尾加入以下
代码如下:
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 )











