Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Snapey's avatar
Level 122

Log file permissions 644 - want 664

On an Ubuntu production server, I have created a sudo'ers account that I log in with. Apache uses the usual www-data account.

If I deploy a new version of my application, and then some activity occurs that creates the log file, then the file is permission 644 and owned by www-data/www-data

My user is in the www-data group but the permissions explicitly exclude group write to the log file.

If I run an artisan command which includes Log statements then the command fails because my user cannot write to the log file.

How can I get Laravel to create the log file with group access so that my user can write to it.

Yes, I can chmod the log file (if it exists) but this is an unwanted complication.

Note that I also have the opposite issue. If the log file is not present and I run the artisan command that causes the log to be created, then now the file is owned by mark and cannot be written to by the framework.

0 likes
3 replies
Snapey's avatar
Level 122

too complicated a question?

click's avatar

I never actually solved it. I just worked my way around it by splitting up log files per 'user. So in the end the CLI had his own log file and the FPM had it's own. And in the end I actually liked the solution because it split up all the log files of artisan tasks in one log file and all the 'user logs' where logged in the other one.

This is what I've added a long time ago L5.1 to bootstrap.php. I think today there are easier ways to configure the log files.

/**
 * Configure Monolog.
 */
$app->configureMonologUsing(function (Monolog\Logger $monolog) {

    // add the current user to the name of the log file to prevent issues with file permissions 
    $filename = storage_path('logs/laravel-' . php_sapi_name() . '.log');

    // automatically remove the oldest logs if we have more than x files
    $maxFiles = 30;

    // create a new rotating log handler
    $handler = new Monolog\Handler\RotatingFileHandler($filename, $maxFiles);

    // prevent the log of having empty [] [] at the end of the log line
    $handler->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true, true));

    // set the handler
    $monolog->pushHandler($handler);
});

Please or to participate in this conversation.