【问题标题】:create directory in /etc with php使用 php 在 /etc 中创建目录
【发布时间】:2016-06-07 09:54:25
【问题描述】:

我想在 /etc/nginx/sites-enabled/ php 中创建一个文件,我已经尝试了很多次,但是 php 不会让我认为我已经修改了 /etc/sudoers 并且我把它们放在了用户 ALL: NOPASSWD : 全部还是不行,谁能告诉我为什么?

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

我的文件 /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

请帮忙!!!

【问题讨论】:

  • 让你的 web 访问 PHP 访问 root 简直太疯狂了。
  • 如果是,实际上我的问题是我想创建一个 php vhost,因为这确实是我的问题
  • 我建议使用通配符 DNS - 例如 *.example.com 和确定请求哪个主机的逻辑。

标签: php linux nginx laravel-5 shell-exec


【解决方案1】:

实现此目标的正确方法是让您的 PHP 页面在任务队列中创建一个条目。该条目只需要包含虚拟主机的新域。然后你应该有另一个以 root 身份运行的进程,它可以检查该主机名并根据需要创建 nginx 记录。

如果您目前没有使用任何任务队列,也可以通过一个简单的 cron 作业来实现。只需在您的数据库中添加一个带有虚拟主机名称的条目。然后让 cron 作业每分钟检查一次该表并制作 nginx 记录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 2016-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多