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);
测试结果为没有权限
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 )
您可能感兴趣的文章:
PHP调用Linux命令无权限的问题解决(visudo)
php exec执行不了
php调用kill命令平滑重启nginx
phpMyAdmin无法载入 mysqli 扩展,请检查 PHP 配置的解决方法
crontab调用shell无法读取环境变量的解决办法
php 502 bad gateway的解决方案
php无法调用外部命令时的处理方法
Navicat for MySQL管理Linux VPS数据库两处连接报错问题
配置mysql允许远程连接
su: /bin/bash: Permission denied错误的解决方法