如何在php中为www-data用户提供所需的特权 [英] How to provide required privilege for www-data user in php
问题描述
我正在尝试执行一个Shell脚本,该脚本会将某些文件夹和文件从一个位置复制到另一个位置.
I am trying to execute a shell script which will copy certain folders and files from one location to another.
但是我正在努力解决一个非常基本的问题-即;从php调用此脚本时,无法复制文件夹或文件.而相同的脚本可以从终端完美运行.是因为那在我执行此脚本时从终端上获得了用户足够的权限来复制/创建文件/文件夹,而从php中调用该脚本时,用户却没有足够的权限?
But I am struggling with a very basic problem - ie; I cannot copy folders or files when I call this script from php. Whereas the same script works perfect from terminal. Is it because that, from terminal when I execute this script, the user has has enough privileges to copy/create files/folders , where as when the script is called from php, the user does not have enough privileges?
对于php, shell_exec('whoami');
说用户是www-data
For php, shell_exec('whoami');
says the user is www-data
我应该怎么做,以使我有足够的特权从php用户www-data进行创建和复制操作
What should I do, in order that, I have enough privileges to do the create and copy operations from php user www-data
非常感谢您的帮助.
推荐答案
添加此内容:
username ALL=NOPASSWD: /path/to/script
在您的sudoers文件中,在/etc/sudoers
中,您也可以使用 visudo
命令编辑该文件.
in your sudoers file, In /etc/sudoers
, you can also use visudo
command to edit that file.
这篇关于如何在php中为www-data用户提供所需的特权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!