16

I am getting this issue for sessions even when I have given 777 and required user and group to the folders in storage.

ErrorException in Filesystem.php line 81: file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec): failed to open stream: Permission denied

How can I get rid of this issue?

at HandleExceptions->handleError('2', 'file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec): failed to open stream: Permission denied', '/var/www/html/business/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php', '81', array('path' => '/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec', 'contents' => 'a:5:{s:6:"_token";s:40:"Dyi8ML8zxaQJOEiVvqBpqk3noLDJTkIdqiC67qs9";s:9:"_previous";a:1:{s:3:"url";s:29:"http://XXXXX:8333";}s:22:"PHPDEBUGBAR_STACK_DATA";a:0:{}s:9:"_sf2_meta";a:3:{s:1:"u";i:1470895812;s:1:"c";i:1470895812;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', 'lock' => true))

Harsimran Singh
  • 698
  • 4
  • 13
  • 29
  • 1
    Have you given a recursive change of permission of all the folders in storage? Could possibly work if you do `chmod -R 777 storage`. – thefallen Aug 11 '16 at 06:49
  • All done and even issue still same – Harsimran Singh Aug 11 '16 at 07:18
  • Maybe this troubleshooting checklist will help you : http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory – Vic Seedoubleyew Aug 20 '16 at 08:42
  • Possible duplicate of [file\_put\_contents(meta/services.json): failed to open stream: Permission denied](https://stackoverflow.com/questions/23540083/file-put-contentsmeta-services-json-failed-to-open-stream-permission-denied) – bharat May 09 '19 at 17:48

9 Answers9

78

I had a problem like that and doing the following solved it for me

chmod -R gu+w storage

chmod -R guo+w storage

php artisan cache:clear

Got it from the answer here

geneowak
  • 978
  • 11
  • 21
  • if none of this is working even after performing all steps mentioned by geneowak then clear browser cookies and cache. it worked for me. –  May 22 '21 at 06:13
  • I am using a VPS `chmod -R guo+w storage` did it for me. Many thanks. – Kingsley Uchenna Sep 02 '23 at 12:10
2

if you try

chmod -R gu+w storage

chmod -R guo+w storage

php artisan cache:clear

and it still doesn't work.

you have two ways:

  1. Disable your SELinux (i really don't recommend this way, unless you are on training or learning)

  2. Configuring SELinux Policies for Apache Web Servers

i want to break down every steps for confirguring selinux policies assumption: you've already installed all database like mysql, postgresql, or others. you've installed web server

  1. install semanage with command "yum provides /usr/sbin/semanage"
  2. install policycoreutils-python with command "yum install -y policycoreutils-python"
  3. create policies:

a. sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html/webapp(/.*)?"

b. sudo semanage fcontext -a -t httpd_log_t "/var/www/html/webapp/logs(/.*)?"

c. sudo semanage fcontext -a -t httpd_cache_t "/var/www/html/webapp/cache(/.*)?"

  1. Allowing ReadWrite Access:

a. sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/webapp/storage(/.*)?"

ACCESS YOUR WEBAPP

b. restorecon -Rv /var/www/html/webapp

1

Giving 777 to the folder session works for me.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Hafsa
  • 29
  • 6
  • Please add further details to expand on your answer, such as working code or documentation citations. – Community Sep 07 '21 at 13:22
  • This is NOT a good approach to define 777 permissions. It's a security risk to your application and system. Please read this answer: https://askubuntu.com/questions/20105/why-shouldnt-var-www-have-chmod-777 – Saud Feb 04 '22 at 14:14
  • @Saud , Why is it not secure while this system requires it? i tried from 000 to 777, and only 777 worked. :( – Tran Quoc Bao Nov 08 '22 at 06:57
  • @TranQuocBao It is considered bad because it allows all the privileges for a file. Means anyone can read and execute your files/scripts which is not that bad, but anyone can also modify your file, which is totally bad. Its the same reason you put a password on your mobile device. Anyone can see your phone. Use your phone to call emergency numbers, but they can't perform any other action. I've mentioned the answer above to better understand. Please read it from there, I can only explain very little in this comment box. Good Day! :) – Saud Nov 17 '22 at 11:30
1

First run this command in your Laravel app folder

sudo composer update

After that run the following in order

sudo chown -R $USER:www-data storage

sudo chown -R $USER:www-data bootstrap/cache

sudo chmod -R 775 storage

sudo chmod -R 775 bootstrap/cache
Nelson Katale
  • 1,309
  • 15
  • 21
1
chown -R www-data:www-data project_folder
sudo service apache2 reload
Dean James
  • 2,491
  • 4
  • 21
  • 29
Ko Ko Gray
  • 11
  • 1
0

chmod -R gu+w storage

chmod -R guo+w storage

php artisan cache:clear

This worked for me for my laravel 8 application.

sohana den
  • 17
  • 3
0

run the following command docker-compose exec <your webserver container name> sh OR bash(if it uses bash) then

ls -l /var/www/storage/framework/views/ | grep 7369b96b4 (this number is part of the file name you are trying to see it permission) you will see something like this -rw-r--r--

the run

chmod 777 var/www/storage/framework/views/7369b96b436adb2109e56fbb8ed7ba805568c985.php(the full file name)

reload the page

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

Go to the session folder and make the permission like 755. It's worked for me.

-1

Goto project root folder and run the following command

sudo chmod -R 777 storage/* bootstrap/cache/*
Md. Juyel Rana
  • 540
  • 5
  • 10