最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP调用Linux命令无权限的问题解决(visudo)
时间:2022-06-24 23:17:18 编辑:袖梨 来源:一聚教程网
业务背景: 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 )
相关文章
- 美国财政部取消加密货币经纪人报告规定 - 详情 07-13
- dreamweaver网页上怎么制作DI5图层? 07-13
- 村上春树经典语录大全81句 07-13
- 燕云十六声真假卧佛任务怎么完成-真假卧佛任务攻略 07-13
- ps怎么处理高低肩? ps照片人物高低肩的调整办法 07-13
- LoginPress PRO v5.0.1 汉化版 自定义WordPress 注册与登录 07-13