简体   繁体   中英

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.

[..] 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM