Using Laravel Artisan and file permissions

眉间皱痕 提交于 2020-08-10 19:37:23

问题


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

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

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

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


回答1:


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

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

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

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.



回答2:


I know this is a really old post but I'd also really advise anyone agains editing your Laravel files over FTP. I used to do this in my pre-Laravel days and it NEVER ended well.

Editing over FTP can have all kinds of problems- dropping connection mid-edit being the least of them. Security and live development errors being a much larger concern.

Develop on your local or dev environment, commit/push to git, then either pipeline to your server or handle your FTP uploads and cleanup after the fact. Pipelines are your best bet if your host will allow them. We use Atlassian BitBucket for ours but the set-up and deployment should be relatively similar for most hosts. Check with your host for documentation on their pipeline set-up:

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

There's also some tutorials online for pipelining straight to FTP (if on a shared host, say):

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




回答3:


It is because you ran a command from root user, try to run the command from the user which you using for edit the project via ftp.



来源:https://stackoverflow.com/questions/34434757/using-laravel-artisan-and-file-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!