Setting User Rights | The Artisan command does not run in code, but works fine on the command line

I have a route, which is essentially a "hook" for running the Artisan command, it takes some get parameters as arguments:

 Route::get('hook', function() { $param = Input::get('param'); Artisan::call('myCommand', array('param' => $param)); } 

myCommand simply creates a directory in the root directory named param and hello.txt .

I can execute myCommand using php artisan myCommand param1 and it works as expected. I can also use the Artisan tinker and run Artisan::call() fine too.

However, when I try to execute a command using a URL (e.g. example.com/hook¶m=hello ), my command does not create anything as expected. If this helps, I try this on Laravel Forge. On my local dev machine, everything is working fine.

Any idea what is wrong?

0
source share
2 answers

You can either set permissions for the folder on

 chmod 777 -R /path/to/folder 

that you absolutely should not do, since everyone can write and execute everything in this directory afterwards

or, what would I prefer, you create a new group, call her in the group:

 sudo groupadd usergroup 

Now that the group exists, add two users to it:

 sudo usermod -a -G usergroup <your username> sudo usermod -a -G usergroup www-data 

Now all that remains is to set the access rights to the directory:

 sudo chgrp -R usergroup /path/to/the/directory sudo chmod -R 770 /path/to/the/directory // <<<<<< change this to 775 

Now only members of a group can read, write, or execute files and folders in a directory. Note the -R argument to the chmod and chgrp commands: this tells them that they recurs to each subdirectory of the target directory and change every available file and directory.

You can also change 770 to something like 774 if you want others to be able to read files, 775 if you want others to read and execute files, etc. Group assignment changes do not take effect until users log out and back.

In your case, you must finally change it to 775 after ...

+4
source

You need to configure directory permissions correctly.

sudo chown -R <YOUR_USERNAME>:www-data <THE_DIRECTORY>

+1
source

All Articles