Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel log file permission problems

If there is an error when running php artisan command the log file will be created like this:

 -rw-rw-r-- 1 user www-data 2,2K Jul 28 18:08 laravel-2019-07-28.log

If there is an error when using app through web browser the log file will be created like this:

-rw-r--r-- 1 www-data www-data 2,2K Jul 28 16:10 laravel-2019-07-28.log

After www-data has created the original file and if there is an error with php artisan command, it will throw an error Permission denied because it can't write to the log

Is there a way to set default chmod for NEW created files, so that they always have rw for group Or you guys have some other solution for this

To reproduce this problem:

  1. delete all storage/logs/*.log files
  2. call some non existing php artisan command for example: php artisan make:xy -> this will make an error and create a .log file
  3. call route in browser /logout -> this will try to write in that same log file and will throw an error that it can't write into log 'Permission denied'
like image 396
lewis4u Avatar asked Jul 28 '19 16:07

lewis4u


1 Answers

Was struggling with this for a long time, and wondered the same thing as the OP, who asked:

Is there a way to set default chmod for NEW created files, so that they always have rw for group

The answer is YES.

In config/logging.php I added permission => 0666, which I found in the Laravel docs, so the config for my daily log now looks like this:

'daily' => [
   'driver' => 'daily',
   'path' => storage_path('logs/laravel.log'),
   'level' => 'debug',
   'days' => 14,
   'permission' => 0666,
],

Just to be clear, 0664 would already be enough to set group permission to rw, but that still resulted in permission errors.

0666 has resolved the permission conflicts for me. Hope this helps someone!

like image 183
kregus Avatar answered Sep 29 '22 03:09

kregus