Solution to Insufficient Permission to Call Linux Commands in PHP

怪我咯
Release: 2023-03-12 16:16:01
Original
2370 people have browsed it

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);
Copy after login

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 )
Copy after login

Solution steps:

The code is as follows:

$ visudo
Copy after login

1)

Comment The following lines

The code is as follows:

#Defaults    requiretty
Copy after login

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
Copy after login

Final test result


The code is as follows:

Array ( [0] => Warning: memory is too small: 1044725760 [1] => test configure is ok )
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template