设置用户权限| Artisan命令不会在代码中运行,但在命令行上可以正常工作 [英] Set user permissions | Artisan command will not run in code but works fine on command line
问题描述
我的路线本质上是运行Artisan命令的钩子",它接受一些get
参数作为参数:
I have a route that is essentially a "hook" to run an Artisan command, it accepts some get
parameters as arguments:
Route::get('hook', function()
{
$param = Input::get('param');
Artisan::call('myCommand', array('param' => $param));
}
myCommand
只需在根目录下创建一个名为param
的目录和一个hello.txt
文件.
myCommand
simply creates a directory in the root called param
and a hello.txt
file.
我可以使用php artisan myCommand param1
正常运行myCommand
,它可以按预期工作.我还可以使用Artisan的tinker
命令并完美运行Artisan::call()
.
I can run myCommand
fine using php artisan myCommand param1
and it works as expected. I can also use Artisan's tinker
command and run Artisan::call()
perfectly fine too.
但是,当我通过访问URL(例如example.com/hook¶m=hello
)尝试命令时,我的命令未按预期创建任何内容.如果也有帮助,我正在Laravel Forge上尝试.在我本地的开发机器上,一切正常.
However when I try the command via visiting the URL (e.g. example.com/hook¶m=hello
), my command does not create anything as expected. If it helps as well, I'm trying this on Laravel Forge. On my local dev machine everything works fine.
有什么想法吗?
推荐答案
您可以通过以下方式为文件夹设置权限
You can either set permissions to the folder by
chmod 777 -R /path/to/folder
绝对不应该做的事情,因为每个人都可以在此目录中编写和执行所有内容
或者,我希望创建一个新组,我们将其称为用户组:
or, what I would prefer, you create a new group, let's call it usergroup:
sudo groupadd usergroup
现在该组已存在,将两个用户添加到其中:
Now that the group exists, add the two users to it:
sudo usermod -a -G usergroup <your username>
sudo usermod -a -G usergroup www-data
现在剩下的就是在目录上设置权限了:
Now all that's left is to set the permissions on the directory:
sudo chgrp -R usergroup /path/to/the/directory
sudo chmod -R 770 /path/to/the/directory // <<<<<< change this to 775
现在,只有用户组组的成员才能读取,写入或执行目录中的文件和文件夹.注意chmod
和chgrp
命令的-R
自变量:这告诉它们递归到目标目录的每个子目录中,并修改每个可用的文件和目录.
Now only members of the usergroup group can read, write, or execute files and folders within the directory. Note the -R
argument to the chmod
and chgrp
commands: this tells them to recurse into every sub directory of the target directory and modify every file and directory available.
如果您希望其他人能够读取文件,则可能还需要将770更改为774,如果您希望其他人读取并执行文件,则可能要更改775,等等.用户注销并重新登录.
You may also want to change 770 to something like 774 if you want others to be able to read the files, 775 if you want others to read and execute the files, etc. Group assignment changes won't take effect until the users log out and back in.
以您的情况为准,之后应将其更改为775 ...
In your case, you should definately change it to 775 afterwards...
这篇关于设置用户权限| Artisan命令不会在代码中运行,但在命令行上可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!