dr200166 2016-06-07 00:41
浏览 96
已采纳

使用php在/ etc中创建目录

I want to create a file in /etc/nginx/sites-enabled/ php, I have tried many times but php will not let think I've already modified the /etc/sudoers and I put them user ALL: NOPASSWD: ALL and still not it works someone can tell me the why?

$result= shell_exec('sudo -u root mkdir /etc/nginx/myfile');

my file /etc/sudoers

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.  
#
Defaults        env_reset
Defaults        exempt_group=sudo
Defaults        mail_badpass
Defaults               secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification
# User alias specification

# Cmnd alias specification
Cmnd_Alias NGINXVHOST = /bin/ln, /bin/mkdir
# User privilege specification
# root  ALL=(ALL:ALL) ALL
root ALL= (ALL) NOPASSWD:ALL
# Members of the admin group may gain root privileges 
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL) NOPASSWD:ALL
vagrant ALL=(ALL) NOPASSWD:ALL
subdominio ALL=(ALL) NOPASSWD:ALL
# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

please help!!!

  • 写回答

1条回答 默认 最新

  • doumu8911 2016-06-07 01:54
    关注

    The proper way to achieve this objective is for your PHP page to create an entry in a task queue. That entry need only contain the new domain for the virtual host. Then you should have another process runnning as root which can check that hostname and create the nginx records as needed.

    If you are not using any task queue at the moment, this can be achieved by a simple cron job as well. Just put an entry in your database with the vhost name. Then have a cron job check that table every minute and make the nginx records.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?