Reputation: 738
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))
Upvotes: 20
Views: 97127
Reputation: 59
remove
in my case, after I added the /storage/framework
from .gitignore
file./storage/framework
line to the .gitignore
file, I faced this error.
Upvotes: 1
Reputation: 601
Deleting the following files on its own can help. It may not be a permissions issue at all. I have the symptoms of this but the only thing that worked was deleting these files :
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
Upvotes: 0
Reputation: 619
Never use 777, the appropriate permissions is it:
if debian based
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chgrp -R www-data ./storage ./bootstrap/cache
chmod -R ug+rwx ./storage ./bootstrap/cache
if RHEL based
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chgrp -R apache ./storage ./bootstrap/cache
chmod -R ug+rwx ./storage ./bootstrap/cache
The important thing here is that the temporary directories are owned by the group that controls Apache.
You must be careful when handling permissions, because there are certain applications of the operating system that if they become vulnerable could access another user's script, so a 777 permission will allow writing it from another user and executing it from another user, which is a security risk.
You must be strict that only the user in question can manage it and, if necessary, the group to which it belongs. It is also recommended that the user have the Apache group assigned. Example:
usermod -aG apache $USER
https://gist.github.com/NeftaliYagua/825b6ce483b92a296caa0f37e4ff040a
Upvotes: 0
Reputation: 37
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
This worked for me for my laravel 8 application.
Upvotes: 2
Reputation: 1
Go to the session folder and make the permission like 755. It's worked for me.
Upvotes: 0
Reputation: 544
Goto project root folder and run the following command
sudo chmod -R 777 storage/* bootstrap/cache/*
Upvotes: -2
Reputation: 21
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
Upvotes: 0
Reputation: 11
chown -R www-data:www-data project_folder
sudo service apache2 reload
Upvotes: 1
Reputation: 1539
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
Upvotes: 12
Reputation: 865
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:
Disable your SELinux (i really don't recommend this way, unless you are on training or learning)
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
- install semanage with command "yum provides /usr/sbin/semanage"
- install policycoreutils-python with command "yum install -y policycoreutils-python"
- 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(/.*)?"
- 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
Upvotes: 2