Home >Backend Development >PHP Tutorial >How to solve the problem of insufficient permissions for calling Linux commands by PHP, phplinux_PHP tutorial

How to solve the problem of insufficient permissions for calling Linux commands by PHP, phplinux_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:07:441191browse

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 )

www.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:...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn