Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File permission of Log in Laravel 5.1

I'm using Laravel 5.1, with Log set to be generated daily.

I'm heavily using Jobs. Web server is Apache, so therefore PHP is executed as apache user, so at the end of the day, a new log file is generated by apache user and file permission is 0644. I've workers configured via Supervisor, which is being run by apache user. (So far so good)

Now for a random spike in Queue, I've a script setup to run more worker (Consumers of Queue). Problem I'm facing is since Log file is generated with 0644 permission, other users doesn't have write permission to file.

Few solutions I can think of is -

  • Start worker from root user (can't do, as I don't have permissions)
  • A cron to change file permission to 0646 at 00:00:00 each day (also requires root)
  • Generate Log file manually at 00:00:00 by current user, so that I would have authority to change permission to 0646 (Can't be reliable, what if apache creates it first)
  • Start the worker as apache user (Since no root, so this is not possible)
  • This Question on Unix SE Site

So my question is what is the best way to do it, it looks like a general problem to me, which any developer could face. Or is there any better way to do this apart from above mentioned methods.

like image 721
Ashwani Agarwal Avatar asked Feb 01 '26 09:02

Ashwani Agarwal


1 Answers

[..] other users doesn't have write permission to file.

Are you sure you want those users to access the file directly? You could just add an API to your laravel app to serve this file (or even only some filtered data from it). This also allows you too have more fine grained access control within your app etc.

like image 158
ZeissS Avatar answered Feb 03 '26 23:02

ZeissS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!