php - 使用php在/etc中创建目录

标签 php linux nginx laravel-5 shell-exec

我想在/etc/nginx/sites-enabled/php 中创建一个文件,我已经尝试了很多次,但是 php 不会让我认为我已经修改了/etc/sudoers 并且我将它们设置为 user ALL: NOPASSWD : ALL 但还是不行有人能告诉我为什么吗?

$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

请帮忙!!!

最佳答案

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

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

关于php - 使用php在/etc中创建目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37668846/

相关文章:

c++ - 每个 cpp 的 nginx 语法高亮显示,无需人工交互

Nginx - 如果 $request_uri 存在 proxy_pass 一个 url,否则另一个 url

php - 如何连接wordpress数据库并插入数据?

php - 在symfony2中填充另一个选择的 "change"事件的选择字段并使其可以提交

linux - 如何在 Fish shell 中设置变量?

python - 在pycharm中运行nupichelloworld

c - 我如何在我的 Linux 虚拟设备驱动程序中检索数据?

php - Zend_Validator_Regex 抛出错误 : Internal error while using the pattern

php - 在 PHP 自引用表单中使用 jQuery 进行表单验证

tomcat - Nginx 反向代理单个 tomcat 实例上的多个应用程序