Storage Cache creates files with different owner/groups? - laravel

I am using Laravel and it works well. After updating one blade file on my local pc and deployed it with git, Laravel can't open that particular blade anymore.
file_put_contents(/var/www/vhosts/***/httpdocs/memberportal/storage/framework/views/8274d2f145c8a134eb15ccbb69c2df396814d64e.php):
failed to open stream: Permission denied (View: /var/www/vhosts/***/httpdocs/memberportal/resources/views/emails/newsletter/2019-04-2/translations/advertise/en.blade.php)
at /var/www/vhosts/***/httpdocs/memberportal/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122,
ErrorException(code: 0): file_put_contents(/var/www/vhosts/***/httpdocs/memberportal/storage/framework/views/8274d2f145c8a134eb15ccbb69c2df396814d64e.php):
failed to open stream: Permission denied at /var/www/vhosts/***/httpdocs/memberportal/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122)
The folder permission and owner of the storage folder and en.blade.php are correct. However, I noticed that the owner/group of the files in the cache are different.
All caches files with owner root:root are not accessible. Any ideas why Laravel changes the ownership of cache files on my production server, when deploying with git? The storage files are ignored by git, so I do not understand how this happens.
Any advice?

Related

Storage symlink doesn't work with Laravel and Vue in Namecheap CPanel (LiteSpeed)

I am trying to access my image files stored inside storage/app/public/subfolder/ using symlink inside /public folder in my Laravel app. Everything works fine in my local setup and also in Jelastic Apache deployment, but it doesn't seem to work in CPanel with LiteSpeed. I am trying to access the files using the link /storage/subfolder/image.png but it is not accessible on CPanel deployment.
I tried creating and deleting storage symlink hundreds of times, but it didn't work. Below are few things I tried:
Deleting and creating symlink again and again using php artisan storage:link command.
Creating symlink using linux command ln -s ../storage/app/public storage inside public folder.
Running Artisan::call('storage:link') using a web route entry.
Redeploying and reconfiguring the app several times and creating storage symlink.
In all of these failed attempts I can verify that storage symlink is created every time inside public folder. I can navigate and view files from public/storage/ folder using CPanel terminal without any issues but can't access them in the deployed app.
I have exact same configuration in Jelastic Apache deployment and in my local deployment and there it is working without any issues.
UPDATE:
Additionally, I tried creating a storage directly manually inside public folder with the same structure and it worked. But symlink doesn't work.
UPDATE 2:
I found below error log while checking error logs from CPanel.
2022-11-06 05:07:07.342556 [ERROR] [1669834] [T0] [HTAccess] Failed to open [/home/user/my-project/public/storage/subfolder/.htaccess]: Permission denied
There is no .htaccess inside subfolder but it is there in my public folder.
What might be the issue?
After making linking you storage to your public path using storage:link you can access your folder :
'Storage_path('subfolder/image.png');'
After a long search, I finally found the cause.
Somehow the storage/app/public directory didn't have sufficient permissions. So, I gave permissions to that public folder recursively using chmod and everything works fine now.
The symlink was working fine but it was not working due to permission issues in the parent folder.
This is a bit weird as I have never manually altered permissions in any Laravel folders in any of my other deployments.

Laravel Cache files losing permissions - Windows 10 IIS & Active Directory

My problem is that when I use caching in Laravel with file driver, I occassionally lose permissions to the cache file. Permissions are set properly, parent folder does not lose any permissions, only the specific cache file. After restarting the machine, permissions are back and I can delete the file manually.
The "permission" error is like:
file_put_contents(C:\inetpub\wwwroot\office_map_dev\storage\framework/cache/data/ca/0d/ca0d727b27eefcb8763203d9ad28f5a5eb29a85e): Failed to open stream: Permission denied

Files system problems

Did clean installation of ddev on my Mac.
Set up Drupal 8 project and have problems with file permissions on sites/default/files folder. For some reason it resets the permissions I set (chmod -R a+w) and web server can't write to this folder afterwards.
Files are owned by uid_1000 gid_50.
Example of the message
Warning: file_put_contents(sites/default/files/php/twig/5c1ad9b345ce5_status-messages.html.twig_3IhisVoQLOYIb64NBegMDuHJs/.htaccess): failed to open stream: Permission denied in Drupal\Component\PhpStorage\FileStorage->ensureDirectory() (line 123 of core/lib/Drupal/Component/PhpStorage/FileStorage.php).

Laravel 5 on Heroku file_put_contents permission issue

I deployed my Laravel 5 app (empty initial app) to Heroku using Github repository and it keeps producing exception
production.ERROR: ErrorException: file_put_contents(/8a232580639f5a7a06b1d497d0825c281c17c91d.php): failed to open stream: Read-only file system in /app/bootstrap/cache/compiled.php:7198
Why would it even try to create a file in the root / directory?
The interesting thing is if I create a new Laravel application and deploy it using Heroku's Git (vs Github repo) it works without problems.
Make sure storage/ path is not ignored. Instead of ignoring the whole storage/ path, replace it with the following in your .gitignore. This can be improved on what are the files and directories that will be created under storage, I haven't much done laravel/lumen in a while so I'm not so sure. But this are the basic ones.
storage/app/*.php
storage/framework/*/*.php

file_put_contents errors in Joomla

I have a Joomla 1.5.20 site and I am not able to upload & update any file in it. The website is running on a Windows Webserver.
Warning: file_put_contents(D:\inetpub\vhosts\hidden\httpdocs\v1\administrator\cache/da4f9e501a6359708d714f016ef2d500.spc) [function.file-put-contents]: failed to open stream: Permission denied in D:\inetpub\vhosts\hidden.tld\httpdocs\v1\libraries\simplepie\simplepie.php on line 8666
Warning: D:\inetpub\vhosts\hidden.tld\httpdocs\v1\administrator\cache/da4f9e501a6359708d714f016ef2d500.spc is not writeable in D:\inetpub\vhosts\hidden.tld\httpdocs\v1\libraries\simplepie\simplepie.php on line 1779
Warning: file_put_contents(D:\inetpub\vhosts\hidden.tld\httpdocs\v1\administrator\cache/da4f9e501a6359708d714f016ef2d500.spc) [function.file-put-contents]: failed to open stream: Permission denied in D:\inetpub\vhosts\hidden.tld\httpdocs\v1\libraries\simplepie\simplepie.php on line 8666
Warning: D:\inetpub\vhosts\hidden.tld\httpdocs\v1\administrator\cache/da4f9e501a6359708d714f016ef2d500.spc is not writeable in D:\inetpub\vhosts\hidden.tld\httpdocs\v1\libraries\simplepie\simplepie.php on line 1779
I have tried deleting and recreating cache folder. Since it is a windows webserver I don't it a permission issue. Please advise me on how to fix it. Thanks!
You need to check your folder permissions:
Login to Administrator panel
Select Help > System info from top menu
Select tab Directory Permissions, all folders listed here need to have 'Writable' permissions.
If any of those folders are Unwritable, login to your server with ftp client, or cPanel, and change folder's CHMOD permissions to 755

Resources