This article mainly introduces how to solve the problem of insufficient permissions for PHP to call Linux commands. This article summarizes the solution to the project problem and solves the problem of no permission to execute commands by modifying the sudo configuration file, for more information, see
This article mainly introduces how to solve the problem of insufficient permissions for PHP to call Linux commands. This article summarizes the solution to the project problem and solves the problem of no permission to execute commands by modifying the sudo configuration file, for more information, see
Business Background: yourcmd is my linux program, which has strict permission requirements. When using php to execute yourcmd Program
System: CentOS 6.3
Apache is the execution user of php.
Execute the program/usr/local/yourcmd/sbin/yourcmd on linux using the exec Function
The php code is as follows:
The 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 );
The test result shows no permission.
The Code is as follows:
Array ([0] => sudo: no tty present and no askpass program specified)
Solution:
The Code is as follows:
$ Mongodo
1) comment out the following lines:
The Code is as follows:
# Defaults requiretty
2) add the following to the end of the file:
The Code is as follows:
Apache ALL = (ALL) NOPASSWD: ALL
Cmnd_Alias yourcmd =/usr/local/yourcmd/sbin/yourcmd
Test result
The Code is as follows:
Array ([0] => Warning: memory is too small: 1044725760 [1] => test configure is OK)
,