使用Laravel Artisan和文件权限

问题描述 投票:0回答:3

我是Laravel的新手,我发现这个框架非常棒。

工匠也很棒,但我使用它有点问题。

假设我用这样的Artisan创建了一个新的Controller

php artisan make:controller Test

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

当我想用我的编辑器在ftp上编辑这个文件时,我不能,因为我没有以root用户身份登录。

有没有办法告诉Artisan创建具有www-data组的文件(例如,不执行chown命令)?

laravel file-permissions artisan
3个回答
7
投票

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

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

www-data替换为您的Web服务器运行的用户名,或者您登录FTP服务的用户名。

当你这样做时,控制器将由www-data拥有,这是你想要的。

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

-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.

0
投票

这是因为您从root用户运行命令,尝试从您用于通过ftp编辑项目的用户运行命令。


0
投票

我知道这是一个非常古老的帖子,但我也建议任何人再次通过FTP编辑你的Laravel文件。我曾经在Laravel之前的日子做过这件事,但从未结束。

通过FTP进行编辑可能会遇到各种各样的问题 - 在编辑中断连接是最不重要的。安全性和实时开发错误是一个更大的问题。

在您的本地或开发环境中开发,提交/推送到git,然后管道到您的服务器或处理您的FTP上传和事后清理。如果您的主机允许,管道是您最好的选择。我们使用Atlassian BitBucket,但对于大多数主机,设置和部署应该相对类似。请与您的主机联系以获取有关其管道设置的文档:

https://www.atlassian.com/continuous-delivery/tutorials/bitbucket-pipelines

还有一些在线教程直接用于管道传输(如果在共享主机上,比如说):

https://www.savjee.be/2016/06/Deploying-website-to-ftp-or-amazon-s3-with-BitBucket-Pipelines/

© www.soinside.com 2019 - 2024. All rights reserved.