2

Let's say my storage/logs directory is empty at the moment. I do a request from Postman and there is an error. So, Laravel attempts to log it to the storage/logs directory. Since it is empty, it creates a new file.

Here it is - please notice the owners/permissions:

-rw-r--r-- 1 www-data www-data 9955 Dec 29 10:29 laravel-2020-12-29.log

I read in this answer that the user should be me (let's call my user myuser) and that both me and the group should have read and write permissions. (and I think that's correct - myuser should be the owner if, for example, I want to run an artisan cmd or sth)

So, I run the following two commands:

sudo chown -R $USER:www-data app/storage
sudo chmod -R ug+w app/storage

Then the permissions of the file become:

-rw-rw-r-- 1 myuser www-data 9955 Dec 29 10:29 laravel-2020-12-29.log

Now, if I try to do a request from Postman again, it still works.

But if I try the next day (or if I delete the file and try again), the new file is created with the initial permissions again:

-rw-r--r-- 1 www-data www-data 9955 Dec 29 10:32 laravel-2020-12-29.log

Why is this happening? What should be done so that the permissions are set to the proper ones?

padawanTony
  • 1,348
  • 2
  • 22
  • 41
  • `sudo chown -R www-data:www-data` then `sudo chmod -R 777 storage` – Kamlesh Paul Dec 29 '20 at 10:59
  • @KamleshPaul what are you talking about? First of all, you should never give 777 permissions to files. Secondly, you are not answering my questions - please take the time to write whole sentences so that we can understand what you're talking about. – padawanTony Dec 29 '20 at 11:08

1 Answers1

3

You can fix this problem with changing the config of your laravel project
Go to this path config/logging.php and find the line which has daily as key and change it like this for example:

'daily' => [
    ...
    'permission' => 0664,
],

After that the log file generate with this permission

azibom
  • 1,769
  • 1
  • 7
  • 21
  • Will this change the user/owner of the file? It will still be created as `-rw-rw-r-- 1 www-data www-data 9955 Dec 29 10:32 laravel-2020-12-29.log` but I want it to be `-rw-rw-r-- 1 myuser www-data 9955 Dec 29 10:32 laravel-2020-12-29.log` – padawanTony Dec 29 '20 at 11:28
  • why do you want to change the owner? – azibom Dec 29 '20 at 11:29
  • I'm not sure it should be changed. I'm just asking based on what I read on the SO_answer I have provided in my question. And, as I'm saying in my question, I think that if the user is `myuser` it will (perhaps?) allow me to do some operations that I couldn't otherwise. If this is wrong, please explain it in your answer so I can accept it. – padawanTony Dec 29 '20 at 11:32
  • That is a log file and usually you don't want to update it with your ide with your user, so you really dont need to change the owner, but anyway if you want to change it you can read about `setfacl` and do it, in short, you say to the `setfacl` that all files that generated in this directory should have this owners, I hope it will be helpful for you – azibom Dec 29 '20 at 11:36
  • If my answer helped you with your question, I would appreciate it if you upvote my answer and choose it as the best answer as you wish. @padawanTony – azibom Dec 29 '20 at 11:52
  • Thank you for yout help. However, your answer does not fully explain/give a solution to my question. I read online that many people have issues with the logs files been created either by the `myuser` or the `www-data` user. Your setfacl suggestion seems to do the trick (from what I read so far) but you need to include in your answer how to use the setfacl cmd in my situation (if the answer is to be complete). – padawanTony Dec 29 '20 at 12:05