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.

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?