Home  >  Article  >  Backend Development  >  Solution to Insufficient Permission to Call Linux Commands in PHP

Solution to Insufficient Permission to Call Linux Commands in PHP

怪我咯
怪我咯Original
2017-07-04 14:21:502354browse

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:

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 is that there is no permission


The code is as follows:

Array ( [0] => sudo: no tty present and no askpass program specified )

Solution steps:

The code is as follows:

$ visudo

1)

Comment The following lines

The code is as follows:

#Defaults    requiretty

2) Add the following


at the end of the file and the code is as follows:

apache ALL=(ALL) NOPASSWD: ALL
Cmnd_Alias yourcmd = /usr/local/yourcmd/sbin/yourcmd

Final test result


The code is as follows:

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!

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