Using Laravel Artisan and file permissions

- 1 answer

Ad

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) ?

Ad

Answer

Ad

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.
Ad
source: stackoverflow.com
Ad