Solution to the problem of insufficient permission for PHP to call Linux commands, phplinux
Business background: yourcmd is my linux program. It has very strict permission requirements. When using php to execute yourcmd program
System: CentOS 6.3
apache is the execution user of php
Use the exec function to execute the program /usr/local/yourcmd/sbin/yourcmd on the linux system
The php code is as follows:
Copy code The code is as follows:
$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);
The test result is no permission
Copy code The code is as follows:
Array ( [0] => sudo: no tty present and no askpass program specified )
Solution steps:
Copy code The code is as follows:
$ visudo
1) Comment out the following lines
Copy code The code is as follows:
#Defaults requiretty
2) Add the following
at the end of the file
Copy code The code is as follows:
apache ALL=(ALL) NOPASSWD: ALL
Cmnd_Alias yourcmd = /usr/local/yourcmd/sbin/yourcmd
Final test results
Copy code The code is as follows:
Array ( [0] => Warning: memory is too small: 1044725760 [1] => test configure is ok )
http://www.bkjia.com/PHPjc/954655.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/954655.htmlTechArticleSolution to the problem of insufficient permissions for PHP to call Linux commands, phplinux business background: yourcmd is my linux program, it has restrictions on permissions The requirements are very strict. When using php to execute yourcmd program system:...