Artisan和文件权限

Artisan和文件权限

本文介绍了使用Laravel Artisan和文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel的新手,我觉得这个框架很棒.

I'm new to Laravel and I find this framework awesome.

工匠也很棒,但是使用它有一些问题.

Artisan is also great but a have a little problem using it.

假设我像这样用工匠创建了一个新的控制器

Let's say that I create a new Controller with Artisan like this

php artisan make:controller Test

在app/Http/Controllers中将有一个名为Test的新文件,该文件的权限将为root:root

There will be a new file in app/Http/Controllers named Test and the permission on this file will be root:root

当我想用我的编辑器通过ftp编辑此文件时,因为我没有以root用户身份登录,所以不能.

When I want to edit this file with my editor over ftp I can't because I'm not logged as root.

是否有任何方法告诉Artisan使用www-data组创建文件(例如,不执行chown命令)?

Is there any ways to tell Artisan to create files with www-data group for example (without doing an chown command) ?

推荐答案

由于您具有root shell访问权限,因此以下命令将使用www-data用户-

Since you have root shell access, the following command will execute another one using the www-data user-

sudo -u www-data php artisan make:controller Test

www-data替换为您的Web服务器所使用的用户名,或者您用来登录FTP服务的用户名.

Replace www-data with whatever the username your web server operates under, or the username you login to the FTP service with.

执行此操作时,控制器将归您想要的www-data所有.

When you do this, the controller will be owned by www-data, which is what you want.

注意:不要永远运行从互联网上复制粘贴的命令,而不能确切知道它们的作用,尤其是在root shell中.在这种情况下,-u参数告诉sudo以特定用户而不是root用户的身份执行命令.在联机帮助页上:

Note: do not ever run commands copy-pasted from the internet without knowing exactly what they do, especially in a root shell.In this case, the -u parameter tells sudo to execute the command as a specific user, not as the root user.From the manpage:

-u user, --user=user
             Run the command as a user other than the default target user (usually root ). The user may be
             either a user name or a numeric user ID (UID) prefixed with the ‘#’ character (e.g.  #0 for UID
             0).  When running commands as a UID, many shells require that the ‘#’ be escaped with a backslash
             (‘\’).  Some security policies may restrict UIDs to those listed in the password database.  The
             sudoers policy allows UIDs that are not in the password database as long as the targetpw option
             is not set.  Other security policies may not support this.

这篇关于使用Laravel Artisan和文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:50