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.

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

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示