web-application-framework laravel

This article explains how to resolve the error:
“The stream or file “laravel.log” could not be opened in append mode: Failed to open stream: Permission denied.”

Thumbnail

Prerequisite

Environment

  • Windows 11
  • Ubuntu 24.04.3 LTS (WSL2 distribution)
  • Docker Engine 28.4.0
  • Amazon Linux 2023(OS of the Docker container)
  • PHP 8.2.15 (fpm-fcgi)
  • NGINX 1.24.0
  • Laravel 11, 12

Fix Permission

Check the permissions of the laravel.log file’s directory.
You can find the directory path in the logging configuration.
In this example, the directory is storage/logs.

drwxr-xr-x root root logs

Currently, only the root user can write log files.
To allow the nginx user to write them, change the owner of the directory to nginx:

$ chown -R nginx:nginx storage

Verify the updated permissions:

drwxr-xr-x nginx nginx logs

Then check whether the error has been resolved.

Change PHP-FPM User

If the error persists, check the PHP-FPM user in the www.conf file, usually located in the /etc/php-fpm.d directory.

If the user is different from nginx (e.g., apache), change it to nginx and restart PHP-FPM:

[www]
user = nginx
group = nginx

Related articles