简体   繁体   English

如何在php中为www-data用户提供所需的特权

[英]How to provide required privilege for www-data user in php

I am trying to execute a shell script which will copy certain folders and files from one location to another. 我正在尝试执行一个Shell脚本,它将某些文件夹和文件从一个位置复制到另一个位置。

But I am struggling with a very basic problem - ie; 但是我正在努力解决一个非常基本的问题-即; I cannot copy folders or files when I call this script from php. 从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调用脚本时,用户没有足够的特权?

For php, shell_exec('whoami'); 对于php, shell_exec('whoami'); says the user is www-data 说用户是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 我应该怎么做,才能拥有足够的特权来从php用户www-data进行创建和复制操作

Any help is much appreciated. 任何帮助深表感谢。

Add this: 添加:

username ALL=NOPASSWD: /path/to/script

in your sudoers file, In /etc/sudoers , you can also use visudo command to edit that file. 在sudoers文件中的/etc/sudoers ,还可以使用visudo命令来编辑该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM