沃梦达 / 编程问答 / php问题 / 正文

设置用户权限 |Artisan 命令不会在代码中运行,但在命令行上可以正常工作

Set user permissions | Artisan command will not run in code but works fine on command line(设置用户权限 |Artisan 命令不会在代码中运行,但在命令行上可以正常工作)

本文介绍了设置用户权限 |Artisan 命令不会在代码中运行,但在命令行上可以正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本质上是运行 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&param=hello)尝试该命令时,我的命令没有按预期创建任何内容.如果它也有帮助,我正在 Laravel Forge 上尝试这个.在我的本地开发机器上一切正常.

However when I try the command via visiting the URL (e.g. example.com/hook&param=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

现在只有用户组组的成员可以读取、写入或执行目录中的文件和文件夹.注意 chmodchgrp 命令的 -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 命令不会在代码中运行,但在命令行上可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:设置用户权限 |Artisan 命令不会在代码中运行,但在命令行上可以正常工作

基础教程推荐