This article mainly introduces the solution to the problem of insufficient command permissions when calling Linux in PHP. This article is a summary of solving project problems. By modifying the sudo configuration file, the problem of not having permission to execute commands is solved. For questions, friends in need can refer to
Business background: yourcmd is my Linux program, which has very strict permission requirements. When using php to execute yourcmd program
System: CentOS 6.3
apache is the execution user of php
Use execfunction to execute the program /usr/local/yourcmd/sbin/yourcmd## on the linux system
#php code is as follows:
<?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 )
Solution steps:
$ visudo
Comment The following lines
#Defaults requiretty
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 )
The above is the detailed content of Solution to Insufficient Permission to Call Linux Commands in PHP. For more information, please follow other related articles on the PHP Chinese website!