The stream or file "/usr/share/nginx/yasan/storage/logs/laravel.log" could not be opened in append mode

Hi. i recently noticed i can not use my Laravel projects on Manjaro somehow. it was working before i install virtual box and now i am facing this problem

The stream or file “/usr/share/nginx/yasan/storage/logs/laravel.log” could not be opened in append mode: Failed to open stream: Read-only file system The exception occurred while attempting to log:

I know it sounds duplicate but trust me. I tried every way i knew and nothing helped me.

So these are the config of everything:
Laravel v10
nginx
php-fpm
Manjaro : Kde plasma

My nginx user is “http”
same as the user and group used in my php-fpm config.

i used this command to change my root project’s owner:

sudo chown -R matinwd:http /usr/share/nginx/yasan
sudo chmod -R 775 /usr/share/nginx/yasan
sudo chmod -R 755 /usr/share/nginx/yasan/storage/*
sudo chmod -R 755 /usr/share/nginx/yasan/bootstrap/*

i tried even laravel commands to clear every cache i think it could be related:

php artisan config:clear
php artisan cache:clear
php artisan optimize:clear
composer dump-autoload

but none of them worked.
I don’t have Selinux installed but even though i tried chcon commands

I restarted nginx service and php-fpm but nothing changed.
I am really tired because of this… can you please help me solve this? thanks in advance.

Well the group is http and you set the permission for the group with g+rx (octal: 5), it have to be writeable: g+rw (octal: 6)

A piece of advise - don’t ever change anything in /usr tree which is not in /usr/local/** - it is likely to be replaced or reset on the next system update.

  • Use /srv/http for websites.
  • Set owner and group to http
  • Use s to ensure files are handled in the context of the http user
  • Add yourself to http group
sudo mkdir -p /srv/http
sudo chown http:http /srv/http -R
sudo chown ug+rws
sudo gpasswd -a $USER http

The last command adds yourself to the http group - logoff for the change to take effect.

2 Likes

I even tried 775 but didn’t worked

oh. but in the document said to write websites on usr/share/nginx/
I am in the http group

sudo cat /etc/group | grep http                                                                                                                              
http:x:33:matinwd

And where should i use s to unsure files are handled in the context of the http user?
Thanks

Best practice is to use /srv/http/domain.tld for files served by a web service - but you should do what you see fit - following best practice will do you best in the long run.

Same practice for ftp, smb, nfs etc.

You use the s when you assign permissions - recursive is optional - only required if the target holds any content

sudo chmod g+ws /srv/http [-R]

Okay i get it
I did this as my case:

sudo chmod g+ws /usr/share/nginx/yasan -R 

and

sudo systemctl restart nginx   

but nothing changed. Still the same error

I guess it could be the cache of something related to nginx or php-fpm but i do not know…
I did clear the cache of browser.

I suggest you make the structure writable by http:http - oh it appears you did that

sudo chmod ug+rw /usr/share/nginx/yasan -R

I see from your initial comment you have set yourself as owner - this should be http - you will have write permissions as you are member of http group

sudo chown http:http /usr/share/nginx/yasan -R

Then restart nginx

sudo nginx -s reload

Unfortunately none of them didn’t work…

Is it a read only file system? If the file system is read only, it doesn’t matter which permissions the file has. Read only is read only.

@xabbu may be on to something - which may be much worse than a permission issue.

You have other problems - e.g. if you are using btrfs and there is an disk error btrfs will load readonly to prevent further damage.

This is no longer a simple permission issue but something completely different.

Oh… So how can i solve it?
It’s ext4 btw… Could it relate to btrfs?

Check permissions.
namei -lx /usr/share/nginx/yasan/storage/logs/laravel.log

Check the service file.
grep "ProtectSystem" /usr/lib/systemd/system/php-fpm.service

Check user in nginx and php-fpm config, reload nginx and php-fpm services just to be sure.

Try to write to the file in a simple PHP script, also check ini_get('open_basedir').

If all above pass then it is an issue with Laravel, or its usage.

2 Likes
f: /usr/share/nginx/yasan/storage/logs/laravel.log
Drwxr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x root root share
drwxrwxr-x http http nginx
drwxrwsrwx http http yasan
drwxrwsrwx http http storage
drwxrwsrwx http http logs
-rwxrwxrwx http http laravel.log

ProtectSystem=full

user in both nginx and php-fpm is http

and for openbase

cat php.ini | grep open_basedir                                                                                                                      ✔ 
; open_basedir, if set, limits all file operations to the defined directory
;open_basedir =
; Note: if open_basedir is set, the cache is disabled

This will block, because path is under /usr, either move the directory out or set it to false.
See: systemd.exec for details.

I would recommend moving it to /srv as linux-aarhus suggested above, or to /var, and trying again.

2 Likes

It really helped… thank all of you guys… but i still can’t why usr/share/nginx/yasan suddenly stopped working after a while… what happened to it?

I have no idea - sorry - but your issue could have been avoided all-together by following best practices - hosting your websites in the /srv/http/** structure.

Yes it helped and solved the problem. thanks! :smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.