First of all why do you want to change the permission of the log file? You want to read it right? Not execute it...
Take a look at this: http://laravel.com/docs/5.1/errors#configuration As it's stated in the documentation you can configure it to a daily file like you have or to a single file or just log the errors and so on
@bobbybouwmann Thanks for your reply.
Because I got this error said Permission denied from nginx. I have to chmod 777 log file, then everything works fine.
2015/07/03 12:16:04 [error] 835#0: *7782 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/rsct/releases/20150703025221/storage/logs/laravel-2015-07-03.log" could not be opened: failed to open stream: Permission denied' in /var/www/rsct/releases/20150703025221/bootstrap/cache/compiled.php:13005
Sorry for hijacking thread. But I run into this problem all the time and I'm not quite sure how to get rid of it.
It seems there are 2 ways log files can be created:
Via the web application. You access the application from the browser and some code wants to write something to the log file. If the log file is not there (e.g. because you use daily logs and nothing has been logged yet) the owner of the log file will be the webserver user, _www in my case.
Via artisan. I use artisan a lot, generate a controller, a migration whatever. If some code that has been triggered via an artisan call throws an exception then artisan wants to write that exception to the log. If the logfile is not there, it will create the logfile but with the user that executed the artisan command as the owner of the logfile.
@1 creates a logfile with permissions 644 and user _www
If artisan needs to write to the log now it has no right to do so and throws an exception.
@2 creates a logfile with permissions 644 and user myMacUser
If the webapplication needs to write to the log now it has no right to do so and throws an exception.
How do you get out of this dilemma (without setting the logfile to single and give everything permission to write to it) ?
I had the same issue with Centos7 ... I tried EVERYTHING. Finally, I found a post on stackoverflow suggesting it could be selinux. I disabled selinux and it worked!
@kobear Your solution will mostly solve my current issue to some extent.
Just to add, I am having similar issue and it seems to be selinux causing. It just doesn't allow php (laravel) create a log file even though file permissions are set to 775 and nginx, php-fpm belongs to same group.
"I had the same issue with Centos7 ... I tried EVERYTHING. Finally, I found a post on stackoverflow suggesting it could be selinux. I disabled selinux and it worked!"
The other solutions seemed to convoluted for me, so I resorted to switching from a daily log file to a single one, to which I assigned the correct access permissions. Since no new files are created by www-data, I don't have to chmod them everyday.
This, however, is fine for local development. In production, I would prefer storing the logs into something like MongoDB, SQLite or even a MySQL table.
The user should then be able to edit /var/www/ files without hassle.
The first line adds the user to the www-data group, the second line clears up any files with messed up ownership, and the third makes it so that all users who are members of the www-data group can read and write all files in /var/www.
If you are logged in as you need to log out and log back in for the group membership to take effect.
The problem arose for me when I started writing debug messages to the log from a custom artisan command.
@kobear
This solution worked perfectly for me, however, there are no line breaks in the logs.
The entire error message is on one line if you look at it using nano, or if I tail it in the console, it's one big jumbled mess. Do you have an idea how to fix this?
An old thread, I know, but don't use 777 permissions for log files, since they do not need to be executable. Use 666if it needs to be readable and writable by multiple users that are not in the same group.
This helped me to understand the issue and what was actually happening. It's been recurring on and off for 2 years on prod servers and I feel like we just actually figured it out.
Envoyer was adding a log file with itself as the user, which the www-data user couldn't access. Envoyer was a part of the www-data group.
By changing the permissions to allow group write access, this issue went away!
I thought I have set the right users and groups, and only 777 worked. I was pulling my hair as to why this happening, and then I realized if 777 allows writing to a directory it means the webserver user is not in the group!
checked the log:
Server/Request Data
USER
"registration"
HOME
"/home/registration"
SCRIPT_NAME
"/index.php"
while I was sure that the user running the server is reg or apache as I set, registration was the user as it was set in Cpanel, Webmin, or Plesk.
DOUBLE-CHECK WHAT IS THE USER IS ACTUALLY WRITING :) hope it helps someone