PHP webpage doesn't launch unix command even after updated sudoers

前端 未结 4 776
时光取名叫无心
时光取名叫无心 2020-12-11 11:29

Basically I am trying to restart a service from a php web page.

Here is the code:



        
相关标签:
4条回答
  • 2020-12-11 11:35

    The problem is not with sudo at the moment, but with SELinux, which is (reasonably) set to deny the HTTPD from gaining root privileges.
    You will need to either explicitly allow this (you can use audit2allow for this), or set SELinux to be permissive instead. I'd suggest the former.

    0 讨论(0)
  • 2020-12-11 11:42

    I encountered the problem recently and the accepted answer above helped. However, I would like to post this answer to elaborate the same, so that the next person does not need to spend time much, like me!

    Follow section 7 of the following link: https://wiki.centos.org/HowTos/SELinux.

    Do grep with httpd_sys_script_t.

    Basically the steps are:

    # grep httpd_sys_script_t /var/log/audit/audit.log | audit2allow -M httpdallowsudo
    # semodule -i httpdallowsudo.pp
    
    0 讨论(0)
  • 2020-12-11 11:53

    The error you are getting seems to be related to your SELinux configuration. You might try temporarily disabling that.

    As an aside, I would strongly suggest that you adjust your sudo configuration to be more restrictive.

    User_Alias WWW=apache
    Cmnd_Alias WEBCMDS=/etc/init.d/portmap
    WWW ALL=NOPASSWD: WEBCMDS
    
    0 讨论(0)
  • 2020-12-11 11:58

    This is probably down to something like trying to execute sudo in a non-interactive shell.

    If you do a grep for 'sudo' in your apache users mail log you might find things like this

    sudo: sorry, you must have a tty to run sudo

    0 讨论(0)
提交回复
热议问题