file_put_contents(meta/services.json): failed to o

2019-01-04 15:43发布

I am new to Laravel. I was trying to open http://localhost/test/public/ and I got

Error in exception handler.

I googled around and changed the permission of storage directory using chmod -R 777 app/storage but to no avail.

I changed debug=>true in app.php and visited the page and got Error in exception handler:

The stream or file "/var/www/html/test/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/test/bootstrap/compiled.php:8423

Then I changed the permissions of storage directory using the command chmod -R 644 app/storage and the 'Error in exception handler' error was gone and a page is loaded. But in there I am getting this:

file_put_contents(/var/www/html/laravel/app/storage/meta/services.json): failed to open stream: Permission denied

29条回答
家丑人穷心不美
2楼-- · 2019-01-04 16:04

FOR ANYONE RUNNING AN OS WITH SELINUX: The correct way of allowing httpd to write to the laravel storage folder is:

sudo semanage fcontext -a -t httpd_sys_rw_content_t '/path/to/www/storage(/.*)?'

Then to apply the changes immediately:

sudo restorecon -F -r '/path/to/www/storage'

SELinux can be a pain to deal with, but if it's present then I'd STRONGLY ADVISE you learn it rather than bypassing it entirely.

查看更多
▲ chillily
3楼-- · 2019-01-04 16:05

Xampp for use:

cd /Applications/XAMPP/htdocs  
chmod -R 775 test/app/storage
查看更多
够拽才男人
4楼-- · 2019-01-04 16:06

some times SELINUX caused this problem; you can disable selinux with this command.

sudo setenforce 0
查看更多
戒情不戒烟
5楼-- · 2019-01-04 16:06

I have the same issue when running vagrant on mac. solved the problem by changing the user of Apache server in https.conf file:

# check user for php
[vagrant] ubuntu ~ $ php -i | grep USER
USER => ubuntu
$_SERVER['USER'] => ubuntu
[vagrant] ubuntu ~ $ 

Run apache under php user instead of user daemon to resolve file access issue with php

# change default apache user from daemon to php user
sudo sed -i 's/User daemon/User ubuntu/g' /opt/lampp/etc/httpd.conf
sudo sed -i 's/Group daemon/Group ubuntu/g' /opt/lampp/etc/httpd.conf

now, php created cache file can be read and edit by apache without showing any access permission error.

查看更多
放荡不羁爱自由
6楼-- · 2019-01-04 16:07

Suggest the correct permission, if for Apache,

sudo chown -R apache:apache apppath/app/storage
查看更多
祖国的老花朵
7楼-- · 2019-01-04 16:08

Any time I change app.php I get a permission denied writing bootstrap/cache/services.json so I did this to fix it:

chmod -R 777 bootstrap/cache/
查看更多
登录 后发表回答