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

codeXX's avatar

Storage folder with permissions 777 but gives error : Failed to open stream Permission Denied

Hello,

I am using Lamp on centos, I have given permission to storage folder 777 but gives failed to open stream Permission denied, following is the permission

drwxrwxrwx.  5 ubaid ubaid     43 Apr 27 18:01 storage

All folders and files have same permissions inside the storage folder. The error I received

ErrorException in Filesystem.php line 109:
file_put_contents(/var/www/testingApi/storage/framework/sessions/81dc54b226f35908288b2753903259bfd723e514): failed to open stream: Permission denied
in Filesystem.php line 109

at HandleExceptions->handleError('2', 'file_put_contents(/var/www/testingApi/storage/framework/sessions/81dc54b226f35908288b2753903259bfd723e514): failed to open stream: Permission denied', '/var/www/testingApi/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php', '109', array('path' => '/var/www/testingApi/storage/framework/sessions/81dc54b226f35908288b2753903259bfd723e514', 'contents' => 'a:3:{s:6:"_token";s:40:"sDXpqJeIvdLfl1T9RnDHxJi4SEoDpoT7SxgcDkjB";s:9:"_sf2_meta";a:3:{s:1:"u";i:1463939936;s:1:"c";i:1463939936;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', 'lock' => true))

at file_put_contents('/var/www/testingApi/storage/framework/sessions/81dc54b226f35908288b2753903259bfd723e514', 'a:3:{s:6:"_token";s:40:"sDXpqJeIvdLfl1T9RnDHxJi4SEoDpoT7SxgcDkjB";s:9:"_sf2_meta";a:3:{s:1:"u";i:1463939936;s:1:"c";i:1463939936;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', '2') in Filesystem.php line 109

at Filesystem->put('/var/www/testingApi/storage/framework/sessions/81dc54b226f35908288b2753903259bfd723e514', 'a:3:{s:6:"_token";s:40:"sDXpqJeIvdLfl1T9RnDHxJi4SEoDpoT7SxgcDkjB";s:9:"_sf2_meta";a:3:{s:1:"u";i:1463939936;s:1:"c";i:1463939936;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', true) in FileSessionHandler.php line 71
at FileSessionHandler->write('81dc54b226f35908288b2753903259bfd723e514', 'a:3:{s:6:"_token";s:40:"sDXpqJeIvdLfl1T9RnDHxJi4SEoDpoT7SxgcDkjB";s:9:"_sf2_meta";a:3:{s:1:"u";i:1463939936;s:1:"c";i:1463939936;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}') in Store.php line 262

at Store->save() in StartSession.php line 88

at StartSession->terminate(object(Request), object(JsonResponse)) in Kernel.php line 155

at Kernel->terminate(object(Request), object(JsonResponse)) in index.php line 58
0 likes
6 replies
TheNodi's avatar

Two things I can think of:

  1. Is SELinux context correct?
  2. Does /var/www/testingApi/storage/framework/sessions/ folder exists?
codeXX's avatar
  1. SELinux context:

Can you please explain, I am not expert in Linux either. How will I allow permissions through SELinux

  1. Folder exist!
TheNodi's avatar

I don't know if SELinux is enabled on centos, run this from root and then try again to see if you get the Permission Denied error.

setenforce 0

This command should set SELinux on permissive mode until the next reboot.

SELinux is a pretty large topic, take a look at the CentOS wiki.

2 likes
codeXX's avatar

Thank you very much! It worked, I'll be sure to look at CentOS wiki.

TheNodi's avatar

Your problem is in the context of the files. By default SELinux say the /var/www folder should be read-only by the apache deamon. You can set a read-write context to the storage folder with: (remember to setenforce 1 to test it out)

chcon -Rt httpd_sys_content_rw_t storage/

To see the current context of file/folders use:

ls -Z
1 like
codeXX's avatar

Thank you! Much appreciated. :)

Please or to participate in this conversation.