PHP has insufficient permissions to call Linux commands. How can this problem be solved?

Source: Internet
Author: User
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)

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.